akhauriyash/Code-Regression huggingface dataset:
import sys

input=sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()


def II(): return int(input())


def MI(): return map(int,input().split())


def MF(): return map(float,input().split())


def LI(): return list(map(int,input().split()))


def LF(): return list(map(float,input().split()))


def TI(): return tuple(map(int,input().split()))


# rstrip().decode('utf-8')


def main():
	n,m,p=MI()
	G=[[] for _ in range(n+1)]
	
	for _ in range(m):
		a,b,c=MI()
		G[a].append([b,c-p])
	#print(G)
	
	coin=[-10**18]*(n+1)
	coin[1]=0
	
	for _ in range(n):
		for i in range(1,n+1):
			for b,c in G[i]:
				coin[b]=max(coin[b],coin[i]+c)
	#print(coin)
	ans=coin[-1]
	
	check=[False]*(n+1)
	for i in range(1,n+1):
		for b,c in G[i]:
			if coin[b]<coin[i]+c and coin[b]>-10**10:
				check[b]=True
	
	for _ in range(n):
		for i in range(1,n+1):
			for b,c in G[i]:
				check[b]=check[i] or check[b]
	#print(check)
	
	if check[n]==True:
		ans=-1
	else:
		ans=max(ans,0)
	
	print(ans)
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

if __name__=="__main__":
	main()


Measured memory_bytes: 75148
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
int n,pset[100007];
long long x[100007],y[100007],ans=0;
pair < pair < long long,long long > , int > p[100007];
vector < pair < long long, pair < int,int > > > cur;
int fset(int x){
    if(pset[x]==x) return x;
    return pset[x]=fset(pset[x]);
}
int main(){
    ios_base::sync_with_stdio(0);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>x[i]>>y[i];
        p[i]=mp(mp(x[i],y[i]),i);
        pset[i]=i;
    }
    sort(p+1,p+1+n);
    for(int i=2;i<=n;i++){
        cur.pb(mp(p[i].fi.fi-p[i-1].fi.fi,mp(p[i].se,p[i-1].se)));
    }
    for(int i=1;i<=n;i++){
        p[i]=mp(mp(y[i],x[i]),i);
    }
    sort(p+1,p+1+n);
    for(int i=2;i<=n;i++){
        cur.pb(mp(p[i].fi.fi-p[i-1].fi.fi,mp(p[i].se,p[i-1].se)));
    }
    sort(cur.begin(),cur.end());
    for(int i=0;i<cur.size();i++){
        int a=cur[i].se.fi,b=cur[i].se.se;
        long long val=cur[i].fi;
        a=fset(a);
        b=fset(b);
        if(a!=b){
            pset[b]=a;
            ans+=val;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 10864
#include <bits/stdc++.h>
using namespace std;
using ll        = long long;
using ld        = long double;
using vl        = vector<ll>;
using vd        = vector<ld>;
using vs        = vector<string>;
using vb        = vector<bool>;
using vvl       = vector<vector<ll>>;
using vvd       = vector<vector<ld>>;
using vvs       = vector<vector<string>>;
using vvb       = vector<vector<bool>>;
using pll       = pair<ll, ll>;
constexpr ll mod= 1e9 + 7;
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for(ll(i)= 0; (i) < (n); (i)++)
#define REPS(i, n) for(ll(i)= 1; (i) <= (n); (i)++)
#define RREP(i, n) for(ll(i)= (n - 1); (i) >= 0; (i)--)
#define RREPS(i, n) for(ll(i)= (n); (i) > 0; (i)--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())
#define YES(n) ((n) ? "YES" : "NO")
#define Yes(n) ((n) ? "Yes" : "No")
#define yes(n) ((n) ? "yes" : "no")

template <class T>
inline void chmin(T& a, T b) {
    if(a > b) { a= b; }
}

template <class T>
inline void chmax(T& a, T b) {
    if(a < b) { a= b; }
}

/* modとる */
inline ll modu(ll a){
    return(a % mod + mod) % mod;
}

/* modつき二項係数 前処理必要*/
const ll binomialmax = 510000;
ll fac[binomialmax], finv[binomialmax], inv[binomialmax];

void cominit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < binomialmax; i++){
        fac[i] = modu(fac[i - 1] * i);
        inv[i] = modu(-inv[mod % i] * (mod / i));
        finv[i] = modu(finv[i - 1] * inv[i]);
    }
}

/* 二項係数計算 */
ll com(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return modu(fac[n] * (modu(finv[k] * finv[n - k])));
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cominit();
    ll N;
    cin >> N;
    ll length = 1;
    ll ans = 0;
    while(N - 3*length >= 0){
        ans += com(N - 2*length - 1,length - 1);
        ans = modu(ans);
        length++;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 15608
#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>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

string stmax(string a, string b) {
    if (a.size() > b.size()) return a;
    else if (a.size() < b.size()) return b;
    else {
        rep(i,a.size()) {
            if (a[i] == b[i]) continue;
            else {
                int x = a[i]-'0', y = b[i]-'0';
                if (x > y) return a;
                else return b;
            }
        }
    }
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    rep(i,m) cin >> a[i];
    vector<int> match = {0,2,5,5,4,5,6,3,7,6};
    vector<string> dp(n+1, "0");
    dp[0] = "";
    rep(i,n) {
        if (dp[i] == "0") continue;
        for (int x : a) {
            if (i+match[x] > n) continue;
            dp[i+match[x]] = stmax(dp[i+match[x]], dp[i]+char('0' + x));
        }
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 61524
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <math.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define debug(x) cout<<x<<endl
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
typedef long long ll;
using namespace std;
const int MAXN=1e5+50;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
//::iterator it;
map<string,int>p;
int main()
{
    std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int n;
    string s;
    cin>>n;
    int ans=0;
    while(n--){
      cin>>s;
      if(p[s]==0)ans++;
      p[s]++;
    }
    cout<<ans<<endl;
    return 0;
}
/*

*/

 
 

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 998244353
using ll = long long;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
using Graph = vector<vector<int>>;

int main(){
    int N,W; cin>>N>>W;
    vector<ll> w(N),v(N);
    rep(i,N)cin>>w.at(i)>>v.at(i);
    vector<vector<ll>> dp(N+1,vector<ll>(100010,INF));//dp[i][v] 価値vにするのに必要な重さの最小値
    dp[0][0] = 0;
    ll res = 0;
    rep(i,N)dp[i][0] = 0;
    rep(i,N){
        rep(j,100010){
            dp[i+1][j] = dp[i][j];
            if(j>=v.at(i))dp[i+1][j] = min(dp[i][j-v.at(i)]+w.at(i),dp[i+1][j]);
            if(dp[i+1][j]<=W)res = max(res,j);
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 83240
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define vpii vector< pair<int,int> >
#define mii map<int,int>
#define MOD 1000000007
#define fr(i,k,n) for(int i=k;i<n;i++)
#define fl(i,k,n) for(int i=k;i>=n;i--)
#define endl "\n"
using namespace std;
typedef long long ll;
int prime[100001]={};
void sieve()
{
	prime[0]=1;
	prime[1]=1;
	for(int i=0;i*i<100001;i++)
	{
		if(prime[i]==0)
		{
			for(int j=i*i;j<100001;j+=i)
			{
				prime[j]=1;
			}
		}
	}
}
ll binpow(ll a,ll b,ll m)
{
	ll res=1;
	while(b>0)
	{

	if(b&1)
	{
		res=res*a%m;
	}
	a=a*a%m;
	b>>=1;
   }
   return res;
}
void solve()
{
	int n;
	cin>>n;
	set<string > s;
	for(int i=0;i<n;i++)
	{
		string x;
		cin>>x;
		s.insert(x);
		
	}
	cout<<s.size()<<endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t=1;
//cin>>t;
while(t--)
{
solve();
}

return 0;
}




Measured memory_bytes: 19216
#include<bits/stdc++.h>
#define FOR(i,l,r) for(int i=l;i<=r;i++)
#define ll long long
#define inf 0x3f3f3f3f

using namespace std;

int n,l;
int A[1000],res=0;
int main(){
    cin>>n>>l;
    for(int i=1;i<=n;i++){
        A[i]=l+i-1;
        res+=A[i];
    }
    sort(A+1,A+1+n);
    int ans=0x3f3f3f3f,mx;
    for(int i=1;i<=n;i++){
        if(abs(res-A[i]-res)<ans){
            mx=res-A[i];
            ans=abs(res-A[i]-res);
        }
    }
    cout<<mx<<endl;
}


Measured memory_bytes: 256
import copy
N, M = map(int, input().split())
A = []
B = []
for i in range(M):
    a, b = map(int, input().split())
    A.append(a - 1)
    B.append(b - 1)


class UnionFind:
    def __init__(self, n):
        self.Parent = [-1 for i in range(N)]

    def root(self, x):
        if self.Parent[x] < 0:
            return x
        self.Parent[x] = self.root(self.Parent[x])
        return copy.deepcopy(self.Parent[x])

    def size(self, x):
        return -copy.deepcopy(self.Parent[self.root(x)])

    def connect(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.size(x) < self.size(y):
            x, y = y, x
        self.Parent[x] += copy.deepcopy(self.Parent[y])
        self.Parent[y] = x
        return True


ans = [0 for i in range(M)]
ans[M - 1] = N * (N - 1) / 2
unif = UnionFind(N)

for i in range(M-1, 0, -1):
    ans[i - 1] = ans[i]
    if unif.root(A[i]) != unif.root(B[i]):
        ans[i - 1] -= unif.size(A[i]) * unif.size(B[i])
        unif.connect(A[i], B[i])

for i in range(M):
    print(int(ans[i]))


Measured memory_bytes: 128984
p = 0
n = int (input ())
l = [int (x) for x in input().split()]
list.sort (l)
x,y,z = 0,1,2
while x < len(l)-2:
  while y < len(l)-1:
    while z < len(l):
      if l[x]!=l[y] and l[x]!=l[z] and l[y]!=l[z] and l[z] < l[x]+l[y]:
        p += 1
      z += 1
    y += 1
    z = y+1
  x += 1
  y = x+1
  z = y+1
print (p)

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    string s,t;
    cin>>s>>t;
    ll sl = s.length();
    ll tl = t.length();
    ll mx=0;
    for(ll i=0;i<=sl-tl;++i)
    {
        ll cnt=0;
        for(ll j=0;j<tl;++j)
        {
            if(s[i+j] == t[j])cnt++;
        }
        mx = max(mx,cnt);
    }
    cout<<tl-mx<<endl;
    return 0;
}




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

int main()
{
  int N = 0;
  std::cin >> N;
  std::vector<int> _d(N);
  auto * const d = &_d[0];
  for (int i = 0; i < N; ++i)
    std::cin >> d[i];
  long long sum = 0;
  for (int i = 0, _i = N - 1; i < _i; ++i)
    for (int j = i + 1; j < N; ++j)
      sum += d[i]*d[j];
  std::cout << sum;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F            first
#define S            second
#define pb(x)        push_back(x)
#define mp(a,b)      make_pair(a,b)
#define mt(a,b,c)    make_tuple(a,b,c)
#define sz           size()
#define all(A)       A.begin(), A.end()
#define mem(a, b)    memset(a, b, sizeof(a))   // all elements of A are b=0 or b=-1 else don't work
#define f0(i,b)      for(ll i=0;i<(b);i++)
#define f1(i,b)      for(ll i=1;i<=(b);i++)
#define f2(i,a,b)    for(ll i=(a);i<=(b);i++)
#define f3(i,b,a)    for(ll i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(ll i=(a);i!=(b);i+=(c))

#define MOD          1000000007 //10^9 + 7
#define PI           acos(-1.0)
#define MAX3(a,b,c)  max(a,max(b,c))

/*------------------------Bitmask-------------------------------*/
#define bitOn(N,pos)      (N | (1LL<<(pos)))
#define bitOff(N,pos)     (N & (~(1LL<<(pos))))
#define bitCheck(N,pos)   ((bool)(N & (1LL<<(pos))))
#define bitFlip(a,k)      (a^(1LL<<(k)))

#define whilee(i,t)  while(i!=t)
#define  sl(a)       scanf("%lld",&a)
#define  pl(a)       printf("%lld\n",a)

//x = 1e18 means 10^18
//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end()); //sort(A, +n, greater<int>());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end()); //will have index if A.begin() is minus from it
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);

//scanf("%lld",&x);
//printf("%lld\n",x);
//printf("%I64d\n", a);
//while (scanf("%lld %lld", &a, &b) == 2)
//printf("Case %lld: %lld\n", t++, a);

/*----------------------- Graph Moves---------------------------*/
// int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1};  // 4 Direction
// int dx[] = {0,0,1,-1,-1,1,-1,1} , dy[] = {-1,1,0,0,1,1-1,-1};  // 8 Direction // Kings Move
// int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};  // Knight Direction
// int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};  // Hexagonal Direction

//vector <ll> A;
//deque <ll> A;
//queue <ll> A;
//stack <ll> A;
//list <int> A;
//set <ll> A;
//map <ll,ll> A;
//unordered_map <ll, ll> A;
//pair <ll,ll> A ;
//tuple <ll, ll, ll> A;
//vector <pair <ll,ll>> A;
//bitset<32> bset1;
//bool ok = true;
//char ch;
//string S, T, U;

ll i=0, j=0, k=0, a, b, c, d, e, f, g, h, l, m, n, o, p, q, r, s, t=1, u, v, w, x, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, flag=0, cnt=0;

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

    // while(cin>>n){}
    cin>>n;
    if(n>=30)
    {
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <inttypes.h>

int main(void){
	long long int n,m;
	long long int ans;

	scanf("%lld %lld",&n,&m);
	if(n!=1&&n!=2){
		if(m!=1&&m!=2){
			ans=(n-2)*(m-2);
		}else if(m==1){
			ans=n-2;
		}else{
			ans=0;
		}
	}else if(n==1){
		if(m!=1&&m!=2){
			ans=m-2;
		}else if(m==1){
			ans=1;
		}else{
			ans=0;
		}
	}else{
		ans=0;
	}
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;

string S[110];

int main() {

	int N, L;

	scanf("%d %d",&N,&L);

	int i;

	for (i = 0; i < N; i++) {
		cin >> S[i];
	}
	sort(S, S + N);

	for (i = 0; i < N; i++) {
		cout << S[i];
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,low,high) for(register int i=(low);i<=(high);++i)
using namespace std;

static int n,c,k; int T[100010];

int main()
{
	scanf("%d%d%d",&n,&c,&k);
	REP(i,1,n) scanf("%d",T+i);
	sort(T+1,T+n+1); int cnt=1,last=1,ans=0;
	REP(i,2,n)
	{
		if(cnt==c) cnt=0,++ans,last=i;
		T[i]>T[last]+k?(cnt=1,++ans,last=i):++cnt;
	}
	return printf("%d\n",ans+(cnt>0)),0;
}

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

using namespace std;
using i64 = long long int;
using ui64 = unsigned long long int;

////////////////////////////////

int main()
{
  int n,m;
  cin >> n >> m;
  vector<int> a(n);
  for(auto&& x:a)cin >> x;
  vector<int> b(m);
  for(auto&& x:b)cin >> x;
  vector<int> c,d;
  c.reserve(n);d.reserve(n);
  for(int i=0;i<b.size();i++){
    for(int j=0;j<b[i];j++){
      if(i&1){
        c.push_back(0);
        d.push_back(1);
      }else{
        c.push_back(1);
        d.push_back(0);
      }
    }
  }
  int lvc = 0, smc = 0, lvd = 0, smd = 0;
  for(int i=0;i<n;i++){
    smc += abs(lvc);
    if(a[i] != c[i]){
      if(c[i])lvc++;
      else lvc--;
    }
    smd += abs(lvd);
    if(a[i] != d[i]){
      if(d[i])lvd++;
      else lvd--;
    }
  }

  if(lvc)smc = 1145141919;
  if(lvd)smd = 1145141919;
  cout << min(smc,smd) << endl;
}




Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()


int main() {
    int n;
    cin >> n;
    vector<int> fs;
    rep (i, n) {
        int f = 0;
        rep (j, 10) {
            int g;
            cin >> g;
            f += (g << j);
        }
        fs.push_back(f);
    }
    vector<vector<int>> profit(n, vector<int>(11));
    rep (i, n) {
        rep (j, 11) {
            cin >> profit[i][j];
        }
    }
    int ans = -1e9;
    rep (i, 1, (1<<10)) {
        int x = 0;
        rep (j, n) {
            int p = fs[j] & i;
            int ctr = 0;
            rep (k, 10) {
                if (p % 2) {
                    ctr++;
                }
                p /= 2;
            }
            x += profit[j][ctr];
        }
        chmax(ans, x);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			while(sc.hasNext()) {
				int m=sc.nextInt();
				int nmin=sc.nextInt();
				int nmax=sc.nextInt();
				if(m==0 && nmin==0 && nmax==0)	break;
				int[] p=new int[m+1];
				for(int i=0; i<m; i++) {
					p[i]=sc.nextInt();
				}
				int gap=0;
				int n=0;
				for(int i=nmin; i<=nmax; i++) {
					if(p[i-1]-p[i]>=gap) {
						gap=p[i-1]-p[i];
						n=i;
					}
				}
				System.out.println(n);
			}
		}
	}
}//11分


Measured memory_bytes: 56388
#include <stdio.h>
#define Free 0
#define Nonfree 1
#define True 0
#define False 1
int Row[8],Colume[8],dpos[15],dneg[15];
int X[8][8];

void Initialization(){
  int i,j;
  for(i=0;i<8;i++){
    Row[i]=Free;
    Colume[i]=Free;
  }
  for(i=0;i<16;i++){
    dpos[i]=Free;
    dneg[i]=Free;
  }
  for(i=0;i<8;i++)
    for(j=0;j<8;j++)
      X[i][j]=False;
}

void backtrack_print(){
  int i,j;
  for(i=0;i<8;i++)
    for(j=0;j<8;j++)
      if(X[i][j]==True)
	if(Row[i]!=j)
	  return ;

  for(i=0;i<8;i++){
    for(j=0;j<8;j++){
      if(Row[i]==j)
	printf("Q");
      else
	printf(".");
    }
    printf("\n");
  }
}

void backtrack(int row){
  int colume;
  if(row==8){
    //Success of set 8 Queens
    backtrack_print();
    return ;
  }

  for(colume=0;colume<8;colume++){
    if(Colume[colume]==Nonfree || dpos[row+colume]==Nonfree || dneg[row-colume+7]==Nonfree)
      continue;

    //set Queens
    Row[row]=colume;
    Colume[colume]=Nonfree;
    dpos[row+colume]=Nonfree;
    dneg[row-colume+7]=Nonfree;

    //search next row
    backtrack(row+1);

    //delete place of Queens
    Row[row]=Free;
    Colume[colume]=Free;
    dpos[row+colume]=Free;
    dneg[row-colume+7]=Free;
  }
  //Failed to set Queens
}

int main(){
  int i,j,row,colume,number;
  Initialization();

  scanf("%d",&number);
  for(i=0;i<number;i++){
    scanf("%d%d",&row,&colume);
    X[row][colume]=True;
  }

  backtrack(0);

  return 0;
}



Measured memory_bytes: 2112
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> a(h);
    for (int i = 0; i < h; ++i) {
        cin >> a[i];
    }
    vvl dp(h, vl(w, 0));
    dp[0][0] = 1;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (j < w - 1 && a[i][j + 1] == '.') {
                dp[i][j + 1] += dp[i][j];
                dp[i][j + 1] %= MOD;
            }
            if (i < h - 1 && a[i + 1][j] == '.') {
                dp[i + 1][j] += dp[i][j];
                dp[i + 1][j] %= MOD;
            }
        }
    }
    cout << dp[h - 1][w - 1] << "\n";
    return 0;
}

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    ll X,K,D; cin>>X>>K>>D;
    ll ans=0;
    if(X==0){
        if(K%2==0){
            cout<<0<<endl;
            return 0;
        }
        if(K%2==1){
            cout<<D<<endl;
            return 0;
        }
    }
    else if(X>0&&(X/K - D)>=0){
        cout<<X-K*D<<endl;
        return 0;
    }
    else if(X<0&&(X/K + D)<=0){
        cout<<-(X+K*D)<<endl;
        return 0;
    }
    else {
        ll A=abs(X)/D;
        if(X>0){
            if(A%2==K%2)ans=abs(X-A*D);
            else ans=abs(X-(A+1)*D);
            cout<<ans<<endl;
            return 0;
        }
        if(X<0){
            if(A%2==K%2)ans=abs(X+A*D);
            else ans=abs(X+(A+1)*D);
            cout<<ans<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 998244353
using namespace std;
int main() {
    int a[] = {1, 1, 1, 2, 1, 2, 1, 5,  2, 2, 1, 5, 1, 2, 1, 14,
               1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << a[k - 1] << endl;
}

Measured memory_bytes: 256
#include "iostream"
using namespace std;

int main()
{
	int n = 0;
	cin >> n; 
	int tmp = 2;
	if(n==1)
	{ 
		cout << n << endl;
	}
	else
	{

		while (n >=tmp)
		{
			tmp *= 2;
		}
		cout << tmp/2 << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<utility>
#include<map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)
#define FORR(i,n,m) for(ll i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K

int main(){
    string str;
    bool a=0,b=0,c=0;
    cin >> str;
    REP(i,3){
        if(str[i]=='a'&&!a){
            //cout << "a";
            a = true;
        }else if(str[i]=='b'&&!b){
            //cout << "b";
            b = true;
        }else if(str[i]=='c'&&!c){
            //cout << "c";
            c = true;
        }
    }
    if(a&&b&&c){cout << "Yes" << endl;}else{cout << "No" << endl;}
    return 0;
}

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

using namespace std;

int main() {
    string tmp, s = "";
    while (cin >> tmp) {
        s += tmp;
    }

    if (s.size() > 4) {
        cout << "NO" << endl;
        return 0;
    }
    int count_1 = 1;
    int count_9 = 1;
    int count_7 = 1;
    int count_4 = 1;
    for (int i = 0; i < s.size(); ++i) {
        //cout << s[i] << endl;
        if (s[i] == '1') {
            if (count_1 == 0) {
                cout << "NO" << endl;
                return 0;
            } else {
                --count_1;
            }
        } else if (s[i] == '9') {
            if (count_9 == 0) {
                cout << "NO" << endl;
                return 0;
            } else {
                --count_9;
            }
        } else if (s[i] == '7') {
            if (count_7 == 0) {
                cout << "NO" << endl;
                return 0;
            } else {
                --count_7;
            }
        } else if (s[i] == '4') {
            if (count_4 == 0) {
                cout << "NO" << endl;
                return 0;
            } else {
                --count_4;
            }
        } else {
            cout << "NO" << endl;
            return 0;
        }
    }
    
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<int> dy = {1, 0};
vector<int> dx = {0, 1};
void drop(vector<vector<char>> &c, int h, int w){
  for (int i = h - 2; i >= 0; i--){
    for (int j = 0; j < w; j++){
      if (c[i][j] != '.' && c[i + 1][j] == '.'){
        int p = i;
        while (c[p + 1][j] == '.'){
          swap(c[p][j], c[p + 1][j]);
          p++;
          if (p == h - 1){
            break;
          }
        }
      }
    }
  }
}
bool win(vector<vector<char>> c, int h, int w, int n){
  bool none = true;
  for (int i = 0; i < h; i++){
    for (int j = 0; j < w; j++){
      if (c[i][j] != '.'){
        none = false;
      }
    }
  }
  if (none){
    return true;
  }
  bool update = false;
  vector<vector<bool>> d(h, vector<bool>(w, false));
  for (int i = 0; i < h; i++){
    for (int j = 0; j < w; j++){
      if (c[i][j] != '.'){
        for (int k = 0; k < 2; k++){
          if (i + dy[k] * (n - 1) < h && j + dx[k] * (n - 1) < w){
            bool same = true;
            for (int l = 0; l < n; l++){
              if (c[i][j] != c[i + dy[k] * l][j + dx[k] * l]){
                same = false;
              }
            }
            if (same){
              update = true;
              for (int l = 0; l < n; l++){
                d[i + dy[k] * l][j + dx[k] * l] = true;
              }
            }
          }
        }
      }
    }
  }
  if (!update){
    return false;
  }
  for (int i = 0; i < h; i++){
    for (int j = 0; j < w; j++){
      if (d[i][j]){
        c[i][j] = '.';
      }
    }
  }
  drop(c, h, w);
  return win(c, h, w, n);
}
int main(){
  int h, w, n;
  cin >> h >> w >> n;
  vector<vector<char>> c(h, vector<char>(w));
  for (int i = 0; i < h; i++){
    for (int j = 0; j < w; j++){
      cin >> c[i][j];
    }
  }
  bool ok = false;
  for (int i = 0; i < h; i++){
    for (int j = 0; j < w - 1; j++){
      vector<vector<char>> c2 = c;
      swap(c2[i][j], c2[i][j + 1]);
      drop(c2, h, w);
      if (win(c2, h, w, n)){
        ok = true;
      }
    }
  }
  if (ok){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 3268
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb1 push_back
#define mod 1000000007LL
#define INF 1234567890

const int maxn = 2e5 + 10;


//initialization here
//

//
//initialization finish


// your function is here
//



//
// your function finished



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

	// your code is here
	//
	int n; cin >> n;
	int a[110];
	int sum = 0;
	rep(i, n)
	{
		cin >> a[i];
		sum += a[i];
	}

	int mean = sum / n;
	if ((sum%n) * 2 >= n) mean++;

	ll ans = 0;
	rep(i, n) ans += (mean - a[i])*(mean - a[i]);

	Print(ans);

	//
	// your code finished

	return 0;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  if(a >= 13){
    cout << b;
  }
  else if(a <= 12 , a >= 6){
    b /= 2;
    cout << b;
  }
  else if(a <= 5){
    cout << 0;
  }
}


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

int main(){
    bool p[200001] = {0};
    int N, M;
    cin >> N >> M;
    bool ans = false;
    for(int i = 0; i < M; ++i){
        int a, b;
        cin >> a >> b;
        if(a < b) swap(a, b);
        if(a == N) if(p[b]){ ans = true; break; } else p[b] = true;
        if(b == 1) if(p[a]){ ans = true; break; } else p[a] = true;
    }
    cout << (ans ? "POSSIBLE\n" : "IMPOSSIBLE\n");
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sca=new Scanner(System.in);
		int a=sca.nextInt();
		int b=sca.nextInt();
		int c=sca.nextInt();
		int x=sca.nextInt();
		int y=0;
		for (int i=0;i<=a;i++) {
		for (int j=0;j<=b;j++) {
			for(int k=0;k<=c;k++) {
				if((500*i)+(100*j)+(50*k)==x) {
					y++;
				}
			}
		}
		}
		System.out.println(y);


	}

}


Measured memory_bytes: 23124
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int a=in.nextInt(),b=in.nextInt(),c=in.nextInt(),d=in.nextInt();
		int i=1,j=1,res1=b,res2=d;
		while(true){
			res1=b*i;
			if(a*i>=n)break;
			i++;
		}
		while(true){
			res2=d*j;
			if(c*j>=n)break;
			j++;
		}
		int res=Math.min(res2,res1);
		System.out.println(res);
	}

}


Measured memory_bytes: 26220
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>
#include <functional>
#include <cassert>

using namespace std;
using ll = long long;

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define ASSERT(cond,mes) assert(cond && mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

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

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

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, (int)v.size())os << v[i] << endl;
    return os;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i*i <= n; ++i) {
        if (n%i == 0) {
            ret.push_back(i);
            if (i != 1 && i*i != n) {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}

template<typename T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

struct ToUpper {
    char operator()(char c) { return toupper(c); }
};

struct ToLower {
    char operator()(char c) { return tolower(c); }
};

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

    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    cin >> A;

    auto solve = [&]() {
        int max = *max_element(ALL(A));
        if (K > max) {
            return false;
        }

        int gcd = A[0];
        REP(i, N) {
            gcd = GCD(gcd, A[i]);
        }
        if (K%gcd == 0)return true;
        return false;
    };
    YESNO(solve(), "POSSIBLE", "IMPOSSIBLE");
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include<algorithm>

using namespace std;


int main() {
	string s;
	cin >> s;
	int len = s.length();

	int ans;
	int cnt = 0;

	for (int i = 0; i < len; i++) {
		if (s[i] == '0' + i % 2) {
			cnt++;
		}
	}
	ans = cnt;
	cnt = 0;
	for (int i = 0; i < len; i++) {
		if (s[i] != '0' + i % 2) {
			cnt++;
		}
	}

	if (ans > cnt) {
		ans = cnt;
	}

	cout << ans << endl;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long 
int F[2100010];

int Mul(int a, int b) {
	return ((a % mod) * (b % mod)) % mod;
}

void fact(void) {
	F[0] = 1;
	F[1] = 1;
	for (int i = 2; i <= 2100000; i++) {
		F[i] = Mul(i, F[i - 1]);
	}
}
int square(int x) {
	return (x * x) % mod;
}

int power(int x, int y) {
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) return square(power(x, y / 2)) % mod;
	else return square(power(x, y / 2)) * x % mod;
}

int Div(int a, int b) {
	return Mul(a, power(b, mod - 2));
}
int P(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	return Div(F[n], F[n - r]);
}

int C(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	int ret;
	ret = Div(F[n], Mul(F[n - r], F[r]));
	return ret;
}
int H(int n, int r) {
	if (n == 0 && r == 0) return 1;
	return C(n + r - 1, r);
}
int dp[100010];
int p[100010];
int N, X;
int f(int X) {
    
    if (dp[X] != -1) return dp[X];
    //cout << X << endl;
    dp[X] = 0;
    auto itr = upper_bound(p, p + N, X);
    itr--;
    int cnt = itr - p + 1;
    if (cnt <= 0) return dp[X] = X;
    rep(i, cnt) {
        dp[X] = (dp[X] + Div(f(X % p[i]), cnt) + mod) % mod;
    }
    //cout << X << " " << cnt << " " << *itr << endl;
    return dp[X];
}


signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> X;
    fact();
    rep(i, N) cin >> p[i];
    sort(p, p + N);
    rep(i, 100010) dp[i] = -1;
    cout << Mul(f(X), F[N]) << endl; 
    //rep(i, X + 1) cout << i << " " << Mul(f(i), F[N]) << endl;

    return 0;
}


Measured memory_bytes: 17408
#!/usr/bin/env python3
import math

def main():
    A, B, H, M = map(int, open(0).read().split())

    X_h = A*math.cos(math.radians(30*H + M/2))
    Y_h = A*math.sin(math.radians(30*H + M/2))
    X_m = B*math.cos(math.radians(6*M))
    Y_m = B*math.sin(math.radians(6*M))
    d = math.sqrt((X_h - X_m)**2 + (Y_h - Y_m)**2)
    print('{:.20f}'.format(d))


main()

Measured memory_bytes: 9528
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
using namespace std;

template<typename T>inline void upmin(T&x,T y){y<x?x=y:0;}
template<typename T>inline void upmax(T&x,T y){x<y?x=y:0;}

typedef unsigned int u32;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int>VI;

const lod pi=acos(-1);
const int oo=1<<30;
const LL OO=1e18;
const int N=310;

int gi(){
	int w=0;bool q=1;char c=getchar();
	while((!isdigit(c))&& c!='-')c=getchar();
	if(c=='-')q=0,c=getchar();
	while(isdigit(c))w=w*10+c-'0',c=getchar();
	return q?w:-w;
}

const int mod=1e9+7;
int f[N][N][2],inv[N],fac[N];

int main(){
	int n=gi(),i,j,k,d,w;
	for(i=fac[0]=1;i<=n;++i) fac[i]=1LL*fac[i-1]*i%mod;
	for(i=2,inv[0]=inv[1]=1;i<=n;i++) inv[i]=mod-1LL*(mod/i)*inv[mod%i]%mod;
	for(i=3;i<=n;++i)inv[i]=1LL*inv[i]*inv[i-1]%mod;
	f[0][0][0]=1;
	for(i=0;i<n;++i){
		d=gi()-1;
		for (j=0;j<=i;++j)
			for (k=0;k<2;++k)
				if(w=f[i][j][k]){
					f[i+1][j][k]=(f[i+1][j][k]+1LL*w*inv[d])%mod;
					if(d){
						f[i+1][j+1][k]=(f[i+1][j+1][k]+1LL*w*inv[d-1])%mod;
						if (!k&&d>1)
							f[i+1][j+1][1]=(f[i+1][j+1][1]+1LL*w*inv[d-2])%mod;
					}
				}
	}
	for (j=3,d=0;j<n;++j)
		d=(d+1LL*f[n][j][1]*fac[j-1]%mod*fac[n-(j-1)-2])%mod;
	d=(d+1LL*f[n][n][0]*fac[n-1])%mod;
	d=1LL*d*((mod+1)>>1)%mod;
	printf("%d\n",d);
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
    int a, b;
    scanf("%d%d", &a, &b);
    if ((a + b) % 2)
        printf("%d\n", (a + b) / 2 + 1);
    else
        printf("%d\n", (a + b) / 2);
    return 0;
}

Measured memory_bytes: 128
while True:
    n, x = map(int, input().split(" "))
    if n == 0 & x == 0:
        break
    
    counter = 0
    for i in range(n):
        num1 = i + 1
        for j in range(n - num1):
            num2 = j + 1 + num1
            for k in range(n - num2):
                num3 = k + 1 + num2
                # print(num1, num2, num3)
                total = sum([num1, num2, num3])
                if total == x:
                    # print(" -> OK")
                    counter += 1
                    
    print(counter)


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

const int MAX = 200;

int main() {
	int H, W;
	cin >> H >> W;
	int c[10][10], A[MAX][MAX];
	for (int i = 0;i < 10;i ++)
		for (int j = 0;j < 10;j ++) cin >> c[i][j];
	for (int i = 0;i < H;i ++) {
		for (int j = 0;j < W;j ++) {
			cin >> A[i][j];
			if (A[i][j] == -1) A[i][j] = 1; // ぶっちゃけ-1って1書かれているのに等しい
		}
	}
	
	for (int i = 0; i < 10; i++) // 経由する頂点
		for (int j = 0; j < 10; j++) // 開始頂点
			for (int k = 0; k < 10; k++) // 終端
				c[j][k] = min(c[j][k], c[j][i] + c[i][k]); // ワーシャルフロイド法
	
	int cost = 0;
	for (int i = 0;i < H;i ++) {
		for (int j = 0;j < W;j ++) {
			cost += c[A[i][j]][1];
		}
	}
	cout << cost;
	return 0;
}

Measured memory_bytes: 384
fun main(args: Array<String>) {
    val split = readLine()!!.split(' ')
    val n = split[0].toInt()
    val x = split[1].toInt()
    val ls = readLine()!!
        .split(' ')
        .map { it.toInt() }
    var count = 1
    var position = 0
    for (l in ls) {
        position += l
        if (position > x) break
        count++
    }
    println(count)
}

Measured memory_bytes: 38216
A, B, C, X, Y = (int(x) for x in input().split())

ans = 0

C *= 2

if(A + B > C):
    ans += min(X, Y) * C
    if(X > Y):
        ans += A * (X - Y)
    else:
        ans += B * (Y - X)
else:
    ans = A * X + B * Y

print(min(ans, C * max(X, Y)))


Measured memory_bytes: 3060
n = int(input())
x = list(map(int, input().split()))
ans = []
l = min(x)
r = max(x)

for i in range(l, r+1):
  tmp = 0
  for j in range(n):
    tmp+= (x[j]-i)*(x[j]-i)
  ans.append(tmp)
print(min(ans))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){

    string s;
    cin >> s;
    bool ans = true;
    for(int i = 0; i < s.size(); i++){
        //cout << i << " " << s[i] << endl;
        if(!i%2 && s[i] !='h') ans = false;
        if(i%2 && s[i] != 'i') ans = false;
    }
    if(s.size() % 2) ans = false;
    if(ans) puts("Yes");
    else puts("No");


}


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

using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define popb pop_back
#define popf pop_front
#define ll long long
#define M 1000000007
#define mod 998244353
#define fs first
#define sc second

int main()
{
  fastio
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  ll int n,k,i,j,c=0;
  cin>>n>>k;
  ll int a[n];
  for(i=0;i<n;i++)
  {
    cin>>a[i];
    if(a[i]>=k)
      c++;
  }
  cout<<c;
  return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define _ << " _ " <<
#define TRACE(x) cerr << #x << " = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define debug
#define TRACE(x)

using namespace std;

typedef long long llint;

const int MAXN = 100010;

struct Fenwick {
  int n, a[MAXN];

  void init(int _n) {
    ++_n;
    n = _n;
    memset(a, 0, sizeof(a));
  }

  void update(int i, int val) {
    ++i;
    for (; i <= n; i += i & -i)
      a[i] += val;
  }

  int get(int i) {
    ++i;
    int ret = 0;
    for (; i > 0; i -= i & -i)
      ret += a[i];
    return ret;
  }
} loga;

inline int min(int a, int b, int c) { return min(min(a,b),c); }

int calc_inversions(vector<int> v) {
  int ret = 0;
  loga.init(100001);
  for (int i = (int)v.size() - 1; i >= 0; --i) {
    ret += loga.get(v[i]);
    loga.update(v[i], 1);
    ret %= 2;
  }
  return ret;
}

int n, a[3][MAXN], p[MAXN], r[MAXN];
int t[MAXN], swaps[MAXN];
int rev[2], inv[2];

int main(void) {
  scanf("%d",&n);
  REP(i, 3) REP(j, n) scanf("%d",&a[i][j]);
  bool valid = true;

  REP(j, n) {
    int mini = min(a[0][j], a[1][j], a[2][j]);
    if (mini % 3 != 1) { valid = false; break; }

    p[j] = mini/3;
    if (a[0][j] == mini && a[1][j] == mini+1 && a[2][j] == mini+2)
      r[j] = 0;
    else if (a[0][j] == mini+2 && a[1][j] == mini+1 && a[2][j] == mini)
      r[j] = 1;
    else
      valid = false;

    if (j % 2 != p[j] % 2) valid = false;
  }
  
  if (!valid) {
    printf("No\n");
    return 0;
  }

  REP(i, n) TRACE(i _ p[i] _ r[i]);

  REP(t, 2) {
    vector<int> v;
    REP(j, n)
      if (p[j] % 2 == t)
	v.push_back(p[j]);
    inv[t] = calc_inversions(v);
    TRACE(inv[t]);
  }

  REP(j, n)
    rev[j % 2] += r[j];
  rev[0] %= 2; rev[1] %= 2;

  TRACE(rev[0]);
  TRACE(rev[1]);

  if (rev[0] != inv[1]) valid = false;
  if (rev[1] != inv[0]) valid = false;

  printf(valid ? "Yes\n" : "No\n");
    
  return 0;
}


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

typedef long long ll;
typedef long long LL;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

#ifdef DEBUG
    #define cek(x) cout<<x
#else
    #define cek(x) if(false){}
#endif // DEBUG

#define fi first
#define se second
#define INF 1000000000
#define INFLL 1000000000000000000LL
#define EPS 1e-9
#define PI acos(-1.0)
#define pb push_back
#define TC() while(tc--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORN(i,n) for(int i=0;i<=n;i++)
#define REP(i,a,b,c) for(int i=a;i<b;i+=c)
#define REPN(i,a,b,c) for(int i=a;i<=b;i+=c)
#define reset(a,b) memset(a,b,sizeof(a))
#define sc(x) scanf("%d",&x)

int arr[300010];

int main(void){
	int n;
	sc(n);
	n*=3;
	FOR(i,n){
		sc(arr[i]);
	}

	sort(arr, arr + n);
	ll tot = 0;
	int ct = 0;
	for(int i = n-2;i>=0;i-=2){
		tot += arr[i];
		ct++;
		if(ct * 3 == n)break;
	}

	cout << tot << endl;

    return 0;
}


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

#if DEBUG && !ONLINE_JUDGE
    #include "header.h"
#else
    #define debug(args...)
#endif

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long lli;
typedef long double ld;

#define pb push_back
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x).size()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(auto i=(a);i<b;i++)

#define INF (int)1e9
#define EPS 1e-9
#define MOD 1000000007
void preprocess(void) {
    return;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(20);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    preprocess();
    int n,k; cin>>n>>k;
    vi dp(n+1, MOD), h(n+1);
    rep(i,1,n+1) cin>>h[i];
    dp[1] = 0;
    rep(i,2,n+1) {
        rep(j,1,k+1) {
            if(i-j<=0) continue;
            dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
        }
    }
    cout<<dp[n]<<endl;
}



Measured memory_bytes: 1024
let count = 0;

const func = (nums: Array<number>) => {
  const isAllEven = nums.every(n => n % 2 === 0);
  if (!isAllEven) return;
  
  count++;
  func(nums.map(n => n / 2));
}

const Main = (input) {
  const [length, nums] = input.split("\n");
  const numsArr = nums.split(' ');
  func(numsArr.map(n => Number(n)));
  console.log(count);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int a,b;
    cin >> a >> b;
    vector<int> l(100);
    int tmp;
    for (int i = 0; i < b; i++) {
       cin >> tmp;
       l[tmp] = 1;
    }
    for (int i = 0; i < 100; i++) {
        if(l[a-i] == 0){
            cout << a-i;
            break;
        }
        if(l[a+i] == 0){
            cout << a+i;
            break;
        }
    }
}


Measured memory_bytes: 3564
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<string>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

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

    vector<ll> a(n);
    ll suma = 0;

    rep(i, n) {
        cin >> a[i];
        suma += a[i];
    }

    vector<ll> b_sub_a(n);
    ll sumb = 0;

    rep(i, n) {
        ll b;
        cin >> b;
        sumb += b;
        b_sub_a[i] = b - a[i];
    }

    if ( sumb > suma ) {
        cout << -1 << endl;
        return 0;
    }

    ll ans = 0;
    ll rest = suma - sumb;

    priority_queue<ll> que;

    rep(i, n) {
        if ( b_sub_a[i] == 0 ) continue;
        else if ( b_sub_a[i] > 0 ) {
            ++ans;
        }
        else {
            que.push(b_sub_a[i]);
        }
    }

    while ( 1 ) {
        if ( que.empty() ) {
            break;
        }

        ll now_num = que.top();
        que.pop();

        if ( rest >= abs(now_num) ) {
            rest += now_num;
        }
        else {
            ++ans;
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
  int N;
  cin >> N;
  
  vector<int> list(N);
  vector<int> num(N);
  
  list.at(0) = 0;
  
  for(int i = 1; i < N; i++){
    cin >> list.at(i);
  }
  
  for (int i = 1; i < N; i++){
    int a = list.at(i) - 1;
    num.at(a)++;
  }
  
  for(int i = 0; i < N; i++){
    cout << num.at(i) << endl;
  }
}

Measured memory_bytes: 4776
// https://atcoder.jp/contests/abc113/tasks/abc113_c
#include <algorithm>
#include <climits>
#include <iomanip>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))

// No、市、年、順位
typedef tuple<int, int, int, int> mytuple;

// int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

// 年でソート（0番目から数えて2番目）
bool mycompare(const mytuple &lhs, const mytuple &rhs) {
    return get<2>(lhs) < get<2>(rhs);
}

int main() {
    int n, m, t1, t2;
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    mytuple tu[m];

    REP(i, m) {
        cin >> t1 >> t2;
        tu[i] = make_tuple(i, t1, t2, 0);
    }
    //年でソート
    sort(tu, tu + m, mycompare);

    // 市の出現回数をメモ
    int cnt[n + 1];
    REP(i, n + 1) cnt[i] = 0;
    REP(i, m) {
        int ct = get<1>(tu[i]);
        cnt[ct]++;
        tu[i] = make_tuple(get<0>(tu[i]), get<1>(tu[i]), get<2>(tu[i]), cnt[ct]);
    }
    // 入力順でソート
    sort(tu, tu + m);
    REP(i, m) {
        cout << setw(6) << std::setfill('0') << (get<1>(tu[i]));
        cout << setw(6) << std::setfill('0') << (get<3>(tu[i])) << endl;
    }

    return 0;
}


Measured memory_bytes: 3456