akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using Matrix  = vector<vector<int>>;
const int INF = 100000000;

Matrix d;

int main() {
  int N, M;
  cin >> N >> M;

  int A[M], B[M], C[M];
  d = Matrix(N, vector<int>(N, INF));
  for (int i = 0; i < N; i++) {
    d[i][i] = 0;
  }

  for (int i = 0; i < M; i++) {
    cin >> A[i] >> B[i] >> C[i];
    A[i]--, B[i]--;
  }

  for (int i = 0; i < M; i++) {
    d[A[i]][B[i]] = min(d[A[i]][B[i]], C[i]);
    d[B[i]][A[i]] = min(d[B[i]][A[i]], C[i]);
  }

  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }

  int ans = M;
  for (int i = 0; i < M; i++) {
    bool flag = false;
    for (int j = 0; j < N; j++)
      if (d[j][A[i]] + C[i] == d[j][B[i]])
        flag = true;
    if (flag)
      ans--;
  }

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

Measured memory_bytes: 256
N = int(input())
S = input()

cnt = 0
for i in range(1, N):
  x = list(set(S[:i]))
  y = list(set(S[i:]))
  tmp = 0
  for c in x:
    if c in y:
      tmp = tmp +1
  
  if cnt < tmp:
    cnt = tmp

print(cnt)

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

int main() 
{
	while (1) {
		int a, b, c, d, e, f;
		cin >> a >> b >> c >> d >> e >> f;
		if (a < 0 || b < 0 || c < 0 || d < 0 || e < 0 || f < 0)break;
		int l, r; l = r = 0;
		for (int g = 1; g < a; g++) {
			if (g % 400 == 0) l += 366;
            else	if (g % 100 == 0)l += 365;
            else    if (g % 4 == 0) l += 366;
            else l += 365;
		}
		for (int g = 1; g < b; g++) {
			switch (g) {
			case 1:case 3:case 5:case 7:case 8:case 10:case 12:l += 31; break;
			case 4:case 6:case 9:case 11: l += 30; break;
			case 2:if (a % 400 == 0) l += 29;
				   else	if (a % 100 == 0)l += 28;
				   else    if (a % 4 == 0) l += 29;
				   else l += 28;
			}
		}
		l += c;
		for (int g = 1; g < d; g++) {
			if (g % 400 == 0) r += 366;
			else	if (g % 100 == 0)r += 365;
			else    if (g % 4 == 0) r += 366;
			else r += 365;
		}
		for (int g = 1; g < e; g++) {
			switch (g) {
			case 1:case 3:case 5:case 7:case 8:case 10:case 12:r += 31; break;
			case 4:case 6:case 9:case 11: r += 30; break;
			case 2:if (d % 400 == 0) r += 29;
				   else	if (d% 100 == 0)r += 28;
				   else    if (d % 4 == 0) r+= 29;
				   else r += 28;
			}
		}
		r += f;
		cout << r - l << endl;
	}
}

Measured memory_bytes: 3000
n,m=map(int,input().split())
a=[0]*(n+1)
b=[0]*(n+1)
for i in range(m):
  x,y=map(int,input().split())
  if x==1:
    a[y]=1
  if y==n:
    b[x]=1
ans=0
for i in range(n+1):
  ans+=a[i]*b[i]
if ans==0:
  print('IMPOSSIBLE')
else:
  print('POSSIBLE')

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

int main() {
	int n; cin >> n;
	int a[n]; for(int i = 0; i < n; ++i) cin >> a[i];
	int64_t ans = 0, tmp = 0;
	for(int i = n - 1; i >= 0; --i) {
		if(a[i] > i or a[i] < tmp) {
			cout << -1 << '\n';
			return 0;
		}
		if(tmp != a[i]) ans += a[i];
		tmp = a[i] - 1;
	}
	cout << ans << '\n';
	return 0;
}


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

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

    int t = 1;
    rep(i, D) t*=100;

    if(N==100) N = 101;
    cout << N*t << endl;
    return 0; 
}

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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define rep(i, n) for(int i = 0; i < n; i++)
#define outl(x) cout<< (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
  return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
  return a / gcd(a, b) * b;
}

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

int n, m;
vi v[10];

int dfs(int idx, int bit, int cnt);

int main()
{
        ci >> n >> m;

        for(int i = 0; i < m; i++) {
                int a, b;
                ci >> a >> b;
                v[a].pb(b);
                v[b].pb(a);
        }

        co << dfs(1, 1, 1) << en;

        return 0;
}

int dfs(int idx, int bit, int cnt)
{
        if(cnt == n) return 1;
        int rec = 0;

        for(int i = 0; i < v[idx].size(); i++) {
                int next = v[idx][i];
                if((1 << (next - 1)) & bit) continue;

                rec += dfs(next, bit | (1 << (next - 1)), cnt + 1);
        }

        return rec;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>

using namespace std;

void solve(long long N, long long C, vector<long long> x, vector<long long> v){
    vector< pair <long long, long long> > sushis;
    for (int i = 0; i < N; i++) {
        sushis.push_back(make_pair(x[i], v[i]));
    }
    sort(sushis.begin(), sushis.end());
    vector< vector<long long> > s(4, vector<long long>(N, 0));
    long long lr = 0;
    long long rr = 0;
    long long lp = 0;
    long long rp = 0;
    long long en = - (sushis[0].first - 0) + sushis[0].second;
    rp = max(en, rp);
    rr = max(en - sushis[0].first, rr);
    s[0][0] = rp;
    s[1][0] = rr;
    for (int i = 1; i < N; i++) {
        en += - (sushis[i].first - sushis[i-1].first) + sushis[i].second;
        rp = max(en, rp);
        rr = max(en - sushis[i].first, rr);
        s[0][i] = rp;
        s[1][i] = rr;
    }
    en = - (C - sushis[N-1].first) + sushis[N-1].second;
    lp = max(en, lp);
    lr = max(en - (C - sushis[N-1].first), lr);
    s[2][0] = lp;
    s[3][0] = lr;
    for (int i = 1; i < N; i++) {
        en += - (sushis[N-i].first - sushis[N-i-1].first) + sushis[N-i-1].second;
        lp = max(en, lp);
        lr = max(en - (C - sushis[N-i-1].first), lr);
        s[2][i] = lp;
        s[3][i] = lr;
    }
    vector<long long> re(2*N);
    for (int i = 0; i < N - 1; i++) {
        re[i] = s[0][i] + s[3][N-i-2];
    }
    re[N-1] = s[0][N-1];
    for (int i = 0; i < N - 1; i++) {
        re[i+N] = s[2][i] + s[1][N-i-2];
    }
    re[2*N-1] = s[2][N-1];
    std::cout << *max_element(re.begin(), re.end()) << std::endl;
}

int main(){	
    struct timeval start,end;
    long long span;
    gettimeofday(&start,NULL);

    long long C;
    long long N;
    scanf("%lld",&N);
    vector<long long> x(N-1+1);
    vector<long long> v(N-1+1);
    scanf("%lld",&C);
    for(int i = 0 ; i <= N-1 ; i++){
    	scanf("%lld",&x[i]);
    	scanf("%lld",&v[i]);
    }
    solve(N, C, x, v);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


Measured memory_bytes: 10608
#include<cstdio>
const int mod=998244353;
inline int add(int a,int b)
{
	return (a+=b)>=mod?a-mod:a;
}
inline int sub(int a,int b)
{
	return (a-=b)<0?a+mod:a;
}
inline int mul(int a,int b)
{
	return (long long)a*b%mod;
}
inline int qpow(int a,int b)
{
	int res=1;
	for(;b;a=mul(a,a),b>>=1)
		if(b&1)
			res=mul(res,a);
	return res;
}
const int N=18;
inline void fwt(int *f,int n,int p)
{
	int w,u,t;
	register int i,j,k;
	for(i=1;i<<1<=n;i<<=1)
		for(j=0;j<n;j+=i<<1)
			for(k=0;k<i;k++)
				u=f[j+k],t=f[j+k+i],f[j+k]=add(u,t),f[j+k+i]=sub(u,t);
	if(!~p)
		for(w=qpow(n,mod-2),i=0;i<n;i++)
			f[i]=mul(w,f[i]);
	return;
}
int n,sum;
int f[1<<N],g[1<<N];
signed main()
{
	register int i;
	scanf("%d",&n);
	for(i=0;i<1<<n;i++)
		scanf("%d",&g[i]),sum=add(sum,g[i]);
	sum=qpow(sum,mod-2);
	for(i=0;i<1<<n;i++)
		g[i]=mul(g[i],sum);
	sum=0;
	fwt(g,1<<n,1);
	for(i=1;i<1<<n;i++)
		f[i]=qpow(sub(g[i],1),mod-2),sum=add(sum,f[i]);
	f[0]=sub(0,sum);
	fwt(f,1<<n,1);
	for(i=0;i<1<<n;i++)
		printf("%d\n",f[i]);
//	putchar('\n');
	return 0;
}

Measured memory_bytes: 4736
#include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <vector>
    #include <string>
    #include <string.h>
     
    typedef long long ll;
    using namespace std;
    const ll INF = 1000000000000000000ll;
    const ll MOD = 1000000007ll;
     
    const double EPS = 1e-8;
     
    int main()
    {
   		string A,B,C;

		cin >> A >> B >>C;

	    cout << 'A' << B[0] << 'C' <<endl;

		return 0;
    }

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

using namespace std;

int p(int k) {
	if (k == 1)return 2; else return 2 * p(k - 1);
}


int main(void) {
	int a, b, c,k;
	cin >> a >> b >> c >> k;
	int m = max(max(a, b), c);

	cout << a + b + c + m*(p(k) - 1);
	return 0;
}

Measured memory_bytes: 256
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}

import           Control.Applicative
import qualified Data.ByteString.Char8 as B
import           Data.Char
import qualified Data.IntSet           as IS
import qualified Data.Vector.Unboxed   as U

main :: IO ()
main = do
    n <- readLn :: IO Int
    xs <- U.unfoldrN n (B.readInt.B.dropWhile isSpace) <$> B.getContents
    print $ solve xs

solve :: U.Vector Int -> Int
solve xs = IS.size $ U.foldl' step IS.empty xs
  where
    step s x = case IS.lookupGE x s of
        Just y | x < y     -> IS.insert x $ IS.delete y s
               | otherwise -> s
        Nothing            -> IS.insert x s

Measured memory_bytes: 14484
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <vector>
#include <stack>

using namespace std;
////////////////*My library*////////////////////////
#define rep_to(a,i,n) for(int i=a;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_r(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) cout<<x<<endl
#define s_1(x) cin>>x
#define s_2(x,y) cin>>x>>y
////////////////////////////////////////////////////

////////////////////////
/*prime()*/
/*primecount()*/
/*sort()*/
/*imos???*/
/*????????¢?´¢*/
/*??±???????????¢?´¢*/
/*???????¨???????*/
///////////////////////
int main()
{
	int a,b,c,d;
	int n[10];
	rep(i,4)cin>>n[i];;

	int t=0;
	rep(i,4)t+=n[i];
	cout<<t/60<<endl;
	cout<<t%60<<endl;
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using longlong=long long;

int main(){
    std::cin.tie(nullptr);std::cin.sync_with_stdio(false);
    int a,b,x;std::cin>>a>>b>>x;
    std::cout<<(a<=x&&x<=a+b?"YES":"NO")<<std::endl;
}

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

long long n, a, b, c, d;

bool solve();

int main() {
  cin >> n >> a >> b >> c >> d;
  if (a > b) swap(a, b);
  if (solve())
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

bool solve() {
  b -= a;
  --n;
  for (int i = 0; i <= n; ++i) {
    long long now = c * (2 * i - n);
    if (now - (d - c) * (n - i) <= b && b <= now + (d - c) * i) return 1;
  }
  return 0;
}

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

int main() {
  int n;
  string s = "No";
  cin >> n;
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      if(i*j == n){s = "Yes";
                   }
    }
  }
    cout << s << endl;
    return 0;
}
   

Measured memory_bytes: 256
#include<iostream>

int main(){
	int n;
	std::cin >> n;
	int ans = -(1<<30);
	int mini;
	std::cin >> mini;
	for (int i = 1; i < n; ++i){
		int a;
		std::cin >> a;
		if (a - mini>ans)ans = a - mini;
		if (mini>a)mini = a;
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x){
  return x * x;
}

signed main (){
  int A,B;
  cin >> A >> B;
  if(A == 1){
A = 14;
  }
  if(B == 1){
B = 14;
  }

if(A > B){
cout << "Alice" << endl;
}else if(A == B){
cout << "Draw" << endl;
}else{
cout << "Bob" << endl;
}
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n;
int a[100100];
int ma,mi=0x3f3f3f3f;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",&a[i]),ma=max(ma,a[i]),mi=min(mi,a[i]);
	if(ma-mi>=2)
	{
		puts("No");
		return 0;
	}
	int c=0;
	if(ma==mi)
	{
		if(mi==n-1||mi*2<=n)
			puts("Yes");
		else puts("No");
	}
	else
	{
		for(int i=1;i<=n;++i)
			if(a[i]==mi)c++;
		if(2*(mi+1-c)>n-c||ma-c<=0)
			puts("No");
		else puts("Yes");
	}
	return 0;
}


Measured memory_bytes: 888
n,m = map(int,input().split())

rList =[[] for i in range(n)] 
for i in range(m):
  a,b = map(int,input().split())
  rList[a-1].append(b)


for i in rList[0]:
  if rList[i-1].count(n) > 0:
    print("POSSIBLE")
    exit(0)
print("IMPOSSIBLE")





Measured memory_bytes: 29592
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
const int M=2e5+4;
const int inf=0x3f3f3f3f;
const ll INF=1e18;
int b[M];

int main(){

    int n,m;
    cin>>n>>m;
    double sum=0;
    for(int i=1;i<=n;i++)
        cin>>b[i],sum+=b[i];
    sort(b+1,b+1+n);
    double tmp=sum/(4.0*m);
    for(int i=n;i>=n-m+1;i--){
        if(1.00*b[i]<tmp)
            return cout<<"No",0;
    }
    cout<<"Yes";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(int argc, char const* argv[])
{
    int n;
    std::cin >> n;
    int origin = n;

    int sum = 0;
    while(true)
    {
        if(n == 0)
        {
            break;
        }
        int tmp = n % 10;
        n = n / 10;
        sum += tmp;
    }

    if((origin % sum) == 0)
    {
        std::cout << "Yes" << std::endl;
    }
    else
    {
        std::cout << "No" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long k = sc.nextLong();
		long count = 0;
		double  sum = 0;


		for(int i=1;i<=Math.min(n,k);i++) {
			for(int j=i;j<k;j*=2) {
				count++;
			}
			sum+=1.0/n * 1.0/Math.pow(2, count);
			count=0;
		}
		for(int i=0;i<n-k;i++) {
			sum+=1.0/n;
		}
		System.out.println(sum);
	}
}




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

using namespace std;
typedef long long ll;

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

	ll n, m; cin >>  n >> m;

	ll P[100005];
	for (int i = 0;i < m;i++){
		cin >> P[i];
	}

	ll A[100005],B[100005],C[100005];
	ll cnt[100005];
	for (int i = 1;i <= n-1;i++){
		cin >> A[i] >> B[i] >> C[i];
		cnt[i] = 0;
	}

	for (int i = 1;i < m;i++){
		ll low = min(P[i-1],P[i]);
		ll high = max(P[i-1],P[i]);
		cnt[low]++;
		cnt[high]--;
	}

	ll sum = 0;
	ll ans = 0;
	for (int i = 1;i <= n-1;i++){
		sum += cnt[i];
		ll cost1 = (ll)A[i]*sum;
		ll cost2 = (ll)B[i]*sum+C[i];
		ans += min(cost1, cost2);
	}

	cout << ans << endl;

	return 0;

}



Measured memory_bytes: 7068
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong n;
bool link[5005][5005];
vector<vector<llong>> v;

inline llong sum(llong x) {
    return x * (x + 1) / 2;
}

int main() {
    cin >> n;
    
    llong k = 1;
    while (sum(k - 1) < n) {
        k++;
    }

    if (sum(k - 1) > n) {
        cout << "No" << endl;
    }
    else {
        llong x = 1;
        v.resize(k + 1);
        for (int i = 1; i <= k; i++) {
            for (int j = 1; j <= k; j++) {
                if (i != j && !link[i][j]) {
                    link[i][j] = link[j][i] = true;
                    v[i].push_back(x);
                    v[j].push_back(x);
                    x++;
                }
            }
        }
        
        cout << "Yes" << endl;
        cout << k << endl;
        for (int i = 1; i <= k; i++) {
            cout << v[i].size() << ' ';
            for (auto a:v[i]) {
                cout << a << ' ';
            }
            cout << endl;
        }
    }

    return 0;
}


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

namespace AtCodr.ABC123.A
{
    class Program
    {
        static void Main(string[] args)
        {
            var nums = new int[5];
            for (var i = 0; i < 5; ++i)
            {
                nums[i] = int.Parse(Console.ReadLine());
            }
            var res = new List<int>();
            for (var i1 = 0; i1 < 5; ++i1)
            {
                for (var i2 = 0; i2 < 5; ++i2)
                {
                    if (i1 == i2) { continue; }
                    for (var i3 = 0; i3 < 5; ++i3)
                    {
                        if (i1 == i3) { continue; }
                        if (i2 == i3) { continue; }
                        for (var i4 = 0; i4 < 5; ++i4)
                        {
                            if (i1 == i4) { continue; }
                            if (i2 == i4) { continue; }
                            if (i3 == i4) { continue; }
                            for (var i5 = 0; i5 < 5; ++i5)
                            {
                                if (i1 == i5) { continue; }
                                if (i2 == i5) { continue; }
                                if (i3 == i5) { continue; }
                                if (i4 == i5) { continue; }
                                var sum = 0;
                                sum = (int)(Math.Ceiling((sum + nums[i1]) / 10f) * 10f);
                                sum = (int)(Math.Ceiling((sum + nums[i2]) / 10f) * 10f);
                                sum = (int)(Math.Ceiling((sum + nums[i3]) / 10f) * 10f);
                                sum = (int)(Math.Ceiling((sum + nums[i4]) / 10f) * 10f) + nums[i5];
                                res.Add(sum);
                            }
                        }
                    }
                }
            }
            Console.WriteLine(res.OrderBy(n => n).First());
        }
    }
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

typedef long long ll;

int main(){
  int n; cin >> n;
  vector<int> a(n); rep(i,n) cin >> a[i];

  map<ll, int> m;

  string ans = "YES";
  rep(i,n){
    m[a[i]]++;
    if(m[a[i]] > 1){
      ans = "NO";
      break;
    }
  }

  cout << ans << endl;

}

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

void Kochcurve(double stX, double stY, double edX, double edY, int n){
	if(n!=0){
		double sX, sY, tX, tY, uX, uY;
		sX = stX + (edX - stX) / 3;
		sY = stY + (edY - stY) / 3;
		tX = stX + (edX - stX) * 2 / 3;
		tY = stY + (edY - stY) * 2 / 3;
		uX = sX + (tX - sX) / 2 - (tY - sY) * sqrt(3) / 2;
		uY = sY + (tX - sX) * sqrt(3) / 2 + (tY - sY) / 2;
		
		Kochcurve(stX,stY,sX,sY,n-1);
		cout << sX << " " << sY << endl;
		Kochcurve(sX,sY,uX,uY,n-1);
		cout << uX << " " << uY << endl;
		Kochcurve(uX,uY,tX,tY,n-1);
		cout << tX << " " << tY << endl;
		Kochcurve(tX,tY,edX,edY,n-1);
	}
}

int main() {
	int n;
	cin>>n;
	cout << 0 << " " << 0 << endl;
	Kochcurve(0,0,100,0,n);
	cout << 100 << " " << 0 << endl;
	return 0;
}

Measured memory_bytes: 1256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using namespace std;
int main(){
  mp::cpp_int n;
  cin >> n;
  mp::cpp_int a, ans=1, flag=0;
  for(int i=0; i<n; i++){
    cin >> a;
    if(ans*a>1000000000000000000){
      flag+=1;
      ans = 1;
	}
    ans *= a;

  }
  if(ans==0)
    cout << ans;
  else if(flag>0)
    cout << -1;
  else
    cout << ans;
  return 0;
}

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

// #include<cstdio>

int main(){
  int n;

  cin >> n;

  for (int i=1; i<=n; i++){
    if (i%3==0){
      cout << ' ' << i;
      continue;
    }
    int x=i;
    while(x){
      if (x%10==3){
	cout << ' ' << i;
	break;
      }
      x /= 10;
    }
  }
  cout << "\n";

  return 0;
}

Measured memory_bytes: 3112
N = int(input())
H = list(map(int, input().split()))
H.reverse()

if N == 1:
  print("Yes")
else:
  for i in range(1, N):
    if i == N-1:
      print("Yes")
    else:
      if H[i] - H[i-1] >= 2:
        print("No")
        break
      elif H[i] - H[i-1] == 1:
        H[i] = H[i] - 1
      else:
        continue

Measured memory_bytes: 15020
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
   if(a%b==0){
      return b;
   }else{
      return gcd(b,a%b);
   }
}
int main(void){
   long long N,M;
   cin>>N>>M;
   string S,T;
   cin>>S>>T;
   long long result=M/gcd(N,M)*N;
   int n=N/gcd(N,M);
   int m=M/gcd(N,M);
   bool flag=true;
   for(int i=0;i<gcd(N,M);i++){
      int temp1=n*i;
      int temp2=m*i;
      if(S[temp1]!=T[temp2]){
         flag=false;
         break;
      }
   }
   if(flag) cout<<result<<endl;
   else cout<<-1<<endl;
   return 0;
}


Measured memory_bytes: 3692
if __name__ == "__main__":
	N, K = map(int, input().split())
	R, S, P = map(int, input().split())
	T = input()
	point = {"r": P, "s": R, "p": S}
	ans = 0
	for i in range(K):
		flag = False
		idx = i
		ans += point[T[idx]]
		while idx + K < N:
			prev_idx = idx
			idx = idx + K
			if T[prev_idx] != T[idx]:
				ans += point[T[idx]]
				flag = False
			else:
				if flag:
					ans += point[T[idx]]
					flag = False
				else:
					flag = True

	print(ans)

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

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

    int n;
    cin >> n;

    vi p(n);
    rep(i, 0, n) { cin >> p[i]; }

    int ans = 0;
    rep(i, 1, n - 1) {
        bool c1 = p[i - 1] < p[i] && p[i] < p[i + 1];
        bool c2 = p[i - 1] > p[i] && p[i] > p[i + 1];
        if (c1 || c2) { ++ans; }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import heapq
from collections import defaultdict
import itertools

N, M, R = list(map(int, input().split()))
Rlist = list(map(int, input().split()))
RX = []

graph = defaultdict(list)

for i in range(M):
	a, b, w = list(map(int, input().split()))
	graph[a - 1].append([b - 1, w])
	graph[b - 1].append([a - 1, w])


for i in range(R):
	dist_node = [float("inf") for j in range(N)]
	dist_node[Rlist[i] - 1] = 0
	Q = []
	heapq.heappush(Q, (dist_node[Rlist[i] - 1], Rlist[i] - 1))

	while Q:
		dis, v = heapq.heappop(Q)
		if dist_node[v] < dis:
			continue
		for u, w in graph[v]:
			alt = dis + w
			if dist_node[u] > alt:
				dist_node[u] = alt
				heapq.heappush(Q, (alt, u))
	RX.append([dist_node[Rlist[k] - 1] for k in range(R)])
	
ans = float("inf")
nl = [i for i in range(R)]
pl = list(itertools.permutations(nl, R))
for i in pl:
	xx = 0
	for j in range(R - 1):
		xx += RX[i[j]][i[j + 1]]

	if xx < ans: 
		ans = xx

print(ans)



Measured memory_bytes: 13264
'use strict';
(function(stdin) {
  //declare function

  //declare variable
  var inputs = stdin.toString().trim().split('\n');
  var line = inputs[1].split(' ').map(Number);
  var result = [];
  line.map(function(v) {
    result.unshift(v);
  });
  //main

  //display
  console.log(result.join(' '));
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 15784
#include <limits>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <bitset>
#include <map>
#include <unordered_map>
#include <cstdint>
using namespace std;

int main(){
    int n,k;
    cin >> n >> k;
    
    cout << (1 + ceil(1.0 * (n - k) / (k - 1))) << '\n';
 
    return 0;
}


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

int main(){
  string s;
  cin >> s;
  string t = s;
  reverse(t.begin(), t.end());
  int count = 0;
  
  rep(i, s.size()){
    if(s.at(i) != t.at(i)){
      count++;
      
    }
  }
  count = count / 2;
  std::cout << count << '\n';
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<random>
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint N, M, A, B;
vector<lint> to[100000];
lint dp[100000];

lint dfs(lint curr) {
	if (dp[curr] != 0) return dp[curr];
	lint maxv = 0;
	REP(i, SZ(to[curr])) {
		chmax(maxv, dfs(to[curr][i]) + 1);
	}
	return dp[curr] = maxv;
}

int main() {
	cin >> N >> M;
	REP(i, M) {
		cin >> A >> B; A--; B--;
		to[A].push_back(B);
	}
	REP(i, N) {
		dp[i] = 0;
	}
	REP(i, N) {
		dfs(i);
	}
	lint maxv = 0;
	REP(i, N) {
		chmax(maxv, dp[i]);
	}
	cout << maxv << endl;
}

Measured memory_bytes: 11896
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	int i,n;
	cin >> n;
	long long a[n],b[n],ans=n;
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	
	sort(a,a+n);
	b[0] = a[0];
	
	for(i=1;i<n;i++){
		b[i] = b[i-1]+a[i];
	}
	
	for(i=0;i<n-1;i++){
		if(a[n-1-i]>2*b[n-2-i]){
			ans = i+1;
			break;
		}
	}
	
	cout << ans << endl;
}
			
	

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

int main() {
	int N;
	cin >> N;
	N %= 10;
	int h[5] = {2, 4, 5, 7, 9}, p[4] = {0, 1, 6, 8}, b[1] = {3};
	int flag = 0;
	for (auto x : h) {
		if (N == x) {
			flag = 1;
		}
	}
	for (auto x : p) {
		if (N == x) {
			flag = 2;
		}
	}
	for (auto x : b) {
		if (N == x) {
			flag = 3;
		}
	}

	if (flag == 1) {
		cout << "hon" << endl;
	} else if (flag == 2) {
		cout << "pon" << endl;
	} else {
		cout << "bon" << endl;
	}
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<string>
#define H_size 100
#define W_size 100

using namespace std;

size_t num = 0;
char list[H_size][W_size];
size_t W, H;

void getNum(char(*a)[W_size], const char c, size_t i, size_t j) {
	if (i < 0 || j < 0 || i >= H || j >= W || a[i][j] !=c) {
		return;
	}
	if (a[i][j] == c)
	{
		a[i][j] = '.';
		getNum(a, c, i - 1, j);
		getNum(a, c, i, j + 1);
		getNum(a, c, i + 1, j);
		getNum(a, c, i, j - 1);
		return;
	}
}

int main() {

	while (true) {
		num = 0;
		cin >> H >> W;
		if (W == 0 && H == 0) {
			break;
		}
		else {
			for (size_t i = 0; i < H; ++i)
			{
				//cin.getline(list[i], W + 1);
				for (size_t j = 0; j < W; ++j) {
					cin >> list[i][j];
				}
			}
		}
		for (size_t i = 0; i < H; ++i) {
			for (size_t j = 0; j < W; ++j)
			{
				if (list[i][j] != '.') {
					getNum(list, list[i][j], i, j);
					num++;
				}
			}
		}
		cout << num << endl;

	}
	return 0;
}

Measured memory_bytes: 1624
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a,b;
    cin>>a;
    cin>>b;
    reverse(b.begin(),b.end());
    if(b==a){
        printf("YES\n");
        return 0;
    }
    printf("NO\n");
    return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
import sys
if M==0:
    print(0,0)
    sys.exit()

AB=[]
for i in range(M):
    a,b=map(str,input().split())
    AB.append([a,b])

AC,WA=0,0
cu=AB[0][0]
L=[[0,0] for i in range(N+1)]

for i in range(M):
    t,s=int(AB[i][0]),AB[i][1]
    if L[t][0]==1:
        continue
    elif s=='AC':
        L[t][0]+=1
    else:
        L[t][1]+=1

for i in range(N+1):
    AC+=L[i][0]
    if L[i][0]==1:
        WA+=L[i][1]

print(AC,WA)

Measured memory_bytes: 34532
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

int n, m, k;
V cnt;

void dfs(int i, int sm) {
    if (i == n) {
        cnt[max<int>(1, sm - k)]++;
        return;
    }

    rep2(d, 1, m + 1) dfs(i + 1, sm + d);
}

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

    while (cin >> n >> m >> k, n) {
        cnt.clear();
        cnt.resize(n * m + 1, 0);
        dfs(0, 0);

        double ans = 0;
        rep(i, cnt.size()) {
            ans += i * cnt[i];
        }
        printf("%.10f\n", ans / pow(m, n));
    }
}

Measured memory_bytes: 3328
n = int(input())

a = []
xy = [[] for i in range(n)]


for i in range(n):
    a.append(int(input()))
    for j in range(a[i]):
        x,y = map(int,input().split())
        xy[i].append([x-1,y])

ans = 0
for i in range(1<<(n)):
    memo = []
    cnt = 0
    for j in range(n):
        if ((i>>j)&1):
            memo.append(1)
            cnt += 1
        else:
            memo.append(0)
    
    cntn = True     
    for j in range(n):
        if memo[j] == 0:
            continue
        for k in range(a[j]):
           prs = xy[j][k][0]

           if memo[prs] != xy[j][k][1]:
               cntn = False
    if not(cntn):
        continue
    ans = max(ans,cnt)

print(ans)




Measured memory_bytes: 3064
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
cnt= float("inf")
for i in range(0,N):
    if abs(A-(T-H[i]*0.006)) < cnt:
        cnt = abs(A-(T-H[i]*0.006))
        ans = i+1
print(ans)

Measured memory_bytes: 9172
N = int(input())
ans = ''
if N == 0:
    print('0')
    quit()
while N != 0:
    if abs(N) % 2 == 1:
        ans = '1' + ans
        N = (N-1) // -2
    else:
        ans = '0' + ans
        N = N // -2

print(ans)

Measured memory_bytes: 2940
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int[] prices = { 100, 101, 102, 103, 104, 105 };
        int index = 5;
        while (x > 0) {
            if (x % 100 == 0) {
                System.out.println(1);
                return;
            } else if (x % 100 < index) {
                index--;
            } else {
                x -= prices[index];
            }
        }

        System.out.println(x == 0 ? 1 : 0);
    }
}

Measured memory_bytes: 21972
N, M = map(int, input().split())
A = list(map(int, input().split()))
CB = []

for _ in range(M):
    b, c = map(int, input().split())
    CB.append((c, b))

CB.sort(reverse=True)
A.sort()
ans = 0
now = 0
count = 0
for i in range(len(A)):
    if A[i] >= CB[now][0]:
        ans += A[i]
    else:
        ans += CB[now][0]
        count += 1
    
    if count == CB[now][1]: # 枚数を超えたら
        count = 0
        now += 1
    if now >= len(CB):
        stoped_idx = i
        ans += sum(A[stoped_idx + 1:])
        break
print(ans)

Measured memory_bytes: 71704
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }


int main(){
    int X;
    cin >> X;
    vector<bool> expo(X + 1);
    expo[1] = true;
    for (int b=2;b<=X;b++) {
        int v = b*b;
        while (v<=X) {
            expo[v] = 1;
            v *= b;
        }
    }
    for (int i=X;i>=1;i--) {
        if (expo[i]) {
            cout << i << endl;
            return 0;
        }
    }
}

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

int main(){
  int n;
  cin >> n;
  ll cnt=0;
  vector<ll> l(n);
  rep(i,n){
    cin >> l.at(i);
  }
  
  rep(i,n-2){
    for(int j=i+1; j<n-1; j++){
      if(l.at(i) == l.at(j)){
        continue;
      }
      for(int k=j+1; k<n; k++){
        if(l.at(i) == l.at(k) || l.at(j) == l.at(k)){
          continue;
        }
        if(abs(l.at(i)-l.at(j)) < l.at(k) && l.at(k) < l.at(i)+l.at(j)){
          cnt++;
        }
      }
    }
  }
  
  cout << cnt << endl;
  
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
#define ll long long
#define ld long double


int main(){

int n;
cin>>n;

vector<int> vec(n+2,0);

int total=0,i=0;
for(i=1;i<=n;i++){
    cin>>vec[i];
    total+=abs(vec[i]-vec[i-1]);
}
total+=abs(vec[i]-vec[i-1]);

for( i=1;i<=n;i++){
    
    cout<<total-(abs(vec[i]-vec[i-1])+ abs(vec[i]-vec[i+1]))+ abs(vec[i+1]-vec[i-1])<<endl;
}
}

Measured memory_bytes: 3408
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())




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

	long long n,a,b,c,d;
	cin>>n>>a>>b>>c>>d;

	if (a>b)swap(a,b);
	rep(i,n){
		int add = i,sub = n-1-i;
		long long mi,ma;
		mi = add*c - sub*d;
		ma = add*d - sub*c;
		if (mi <= abs(a-b) && abs(a-b) <= ma){
			cout << "YES"<<endl;
			return 0;
		}
	}
	cout << "NO"<<endl;

	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
import itertools

def main():
    n, m, q = map(int, input().split())
    list_ = []
    for _ in range(q):
        list_.append(list(map(int, input().split())))

    seq = (i for i in range(m))
    comb_list = list(itertools.combinations_with_replacement(seq, n))

    max_s = 0
    for comb in comb_list:
        score = 0
        for i in range(q):
            a, b, c, d = list_[i]
            if comb[b-1] - comb[a-1] == c:
                score += d
        if score > max_s:
            max_s = score

    print(max_s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 21492
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix
 
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline  #危険！基本オフにしろ！
 
def main():
    n=int(input())
    print((n-1)*n//2)
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 5228
import bisect
N, W = map(int, input().split())
min_w = []
for i in range(N):
  w, v = map(int, input().split())
  l = [w] * v + [i + w for i in min_w]
  min_w = [min(min_w[i], l[i]) for i in range(len(min_w))] + l[len(min_w):]
#  print(min_w, len(min_w))
print(bisect.bisect_right(min_w, W))

Measured memory_bytes: 16820
#include <bits/stdc++.h>
using namespace std;
#define m 1000000007
main()
{
    int h,w;
    cin >> h >> w;
    char mat[h][w];
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
            cin >> mat[i][j];
    }

    int dp[h][w];
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    for(int i=0;i<h;i++)
    {
        if(mat[i][0]=='.')
            dp[i][0]=1;
        else
            break;
    }

    for(int i=0;i<w;i++)
    {
        if(mat[0][i]=='.')
            dp[0][i]=1;
        else
            break;
    }

    for(int i=1;i<h;i++)
    {
        for(int j=1;j<w;j++)
        {
            if(mat[i][j]=='#')
                continue;
            if(dp[i-1][j]>0)
            dp[i][j]+=dp[i-1][j];
            if(dp[i][j-1]>0)
            dp[i][j]+=dp[i][j-1];

            if(dp[i][j]>m)
                dp[i][j]-=m;
        }
    }
    

    cout << dp[h-1][w-1] << endl;
}

Measured memory_bytes: 5120
n,s= map(int, input().split())
a= list(map(int, input().split()))

mod=998244353
#dp[i][j]:i番目まで見て値がjである集合の個数
dp=[[0]*(s+1) for i in range(n+1)]
dp[0][0]=1

for i in range(n):
    for j in range(s+1):
        dp[i+1][j]+=dp[i][j]*2
        dp[i+1][j]%=mod
        if j+a[i]<=s:
            dp[i+1][j+a[i]]+=dp[i][j]
            dp[i+1][j+a[i]]%=mod

print(dp[-1][-1])

Measured memory_bytes: 139168
// Package main provides
//
// File:  d.go
// Author: ymiyamoto
//
// Created on Mon Dec 17 14:30:43 2018
//
package main

import "fmt"

func nums(n int64) int64 {
	if n == 0 {
		return 1
	}
	return 3 + 2*nums(n-1)
}

func middle(n int64) int64 {
	return (nums(n) + 1) / 2
}

func pathis(n, x int64) int64 {
	if x == 0 {
		return 0
	}

	if n == 0 && x == 1 {
		return 1
	}

	mid := middle(n)
	if x < mid {
		return pathis(n-1, x-1)
	} else if x == nums(n) {
		return 1 + 2*pathis(n-1, nums(n-1))
	} else {
		return 1 + pathis(n-1, nums(n-1)) + pathis(n-1, x-mid)
	}
}

func main() {
	var N, X int64
	fmt.Scan(&N, &X)
	fmt.Println(pathis(N, X))
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main()
{
	/*int n;
	cin >> n;
	cout << (n + 1) / 2;*/


	int a[3][3];
	rep(i, 3)rep(j, 3) {
		cin >> a[i][j];
	}
	int n;
	cin >> n;
	int b;
	vector<vector<int>>c(3, vector<int>(3));
	rep(i, n) {
		cin >> b;

		rep(j, 3) {
			rep(k, 3) {
				if (b == a[j][k])c[j][k] = 1;
			}
		}
	}
	bool ok = false;
	int x = 0, y = 0;

	rep(i, 3) {
		x = 0;
		y = 0;
		rep(j, 3) {
			x += c[i][j];
			y += c[j][i];
		}
		if (x == 3 || y == 3)ok = true;
	}
	int z = 0, z2 = 0;
	z = c[0][0] + c[1][1] + c[2][2];
	z2 = c[2][0] + c[1][1] + c[0][2];
	if (z == 3 || z2 == 3)ok = true;

	if (ok)puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
// Winners don't quit and Quitters don't win
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mod 998244353
#define MAX 100005
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll x,y,a,b,c,i,j,v,k,d1,d2,ans=0,id1,id2;
    vll v1,v2,v3,v4;
    cin>>x>>y>>a>>b>>c;
    for(i=0;i<a;++i){
    	cin>>v;
    	v1.pb(v);
	}
	for(i=0;i<b;++i){
    	cin>>v;
    	v2.pb(v);
	}
	for(i=0;i<c;++i){
    	cin>>v;
    	v3.pb(v);
	}
	sort(v1.begin(),v1.end(),greater<ll>());
	sort(v2.begin(),v2.end(),greater<ll>());
	sort(v3.begin(),v3.end(),greater<ll>());
	for(i=0;i<x;++i){
		v4.pb(v1[i]);
	}
	for(i=0;i<y;++i){
		v4.pb(v2[i]);
	}
	for(i=0;i<v4.size();++i){
		ans+=v4[i];
	}
	sort(v4.begin(),v4.end(),greater<ll>());
	id1=0;
	j=v4.size()-1;
	while(id1<c){
		d1=v3[id1]-v4[j];
		if(d1>0){
			ans+=d1;
			id1++;
			j--;
		}
		else{
			break;
		}
	}
	cout<<ans;
}

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

using namespace std;
const int N=1e3+10;


int from[N*2], to[N*2];
int n, m;
vector<int> V[N];
int vis[N], F[N];
int ans;
map<int, map<int, int>> p;

int bfs(int st) {
	queue<int> Q;
	memset(vis, -1, sizeof(vis));
	memset(F, 0, sizeof(F));
	Q.push(st);
	vis[st]=1;
	F[st]=0;
	while(!Q.empty()) {
		int cur=Q.front();Q.pop();
		for(auto k:V[cur]) {
			int u=to[k];
			if (u==st) return ans=cur;
			if (vis[u]!=-1) continue;
			vis[u]=vis[cur]+1;
			F[u]=cur;
			Q.push(u);
		}
	}
	return ans=-1;
}

int main() {
	cin>>n>>m;
	for(int i=1; i<=m; i++) {
		cin>>from[i]>>to[i];
		V[from[i]].push_back(i);
	}
	int len=12345678;
	int A=0;
	for(int i=1; i<=n; i++) {
		int tmp=bfs(i);
		if (tmp==-1) continue;
		if (vis[tmp]<len) {
			A=i;
			len=vis[tmp];
		}
	}
	if (!A) {
		cout<<-1<<endl;
		return 0;
	}
	bfs(A);
	cout<<len<<endl;
	for(int i=1; i<=len; i++) {
		cout<<ans<<endl;
		ans=F[ans];
	}
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
    ll n;
    cin >> n;
    ll a[n];
    for(ll i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    ll po = a[n - 1];
    ll yo = a[0];
    for(ll i = 0; i < n - 1; i++){
        if(abs((po + 1)/ 2 - yo) > abs((po + 1) / 2 - a[i])) yo = a[i];
    }
    cout << po << " " << yo << endl;
    return 0;
}

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

int main(){
  int L,N;
  cin >> N >> L ;
  vector<string> str(N);
  vector<string> ans(N);
  for(int i=0; i<N; i++)
    cin >> str.at(i);
  
  sort(str.begin(),str.end());
  for(int i=0; i<N; i++)
    cout << str.at(i);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int> u(N);
  for(int &i:u)
    cin>>i;
  sort(u.begin(),u.end());
  long double j=u[0];
  for(int i=1;i<N;i++)
    j=(j+u[i])/2;
  cout<<fixed<<setprecision(16)<<j<<endl;
}

Measured memory_bytes: 3700
import std.algorithm;
import std.conv;
import std.stdio;
import std.string;
import std.math;

void main()
{
	auto ab = readln.split.map!( to!int );
	
	auto add = ab[ 0 ] + ab[ 1 ];
	auto sub = ab[ 0 ] - ab[ 1 ];
	auto mul = ab[ 0 ] * ab[ 1 ];
	
	writeln( max( add, sub, mul ) );
}


Measured memory_bytes: 256
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, input().rstrip('\n').split()))
    s = str(input().rstrip('\n'))
    cnt = 0
    for i in range(1, n):
        if s[i-1] == s[i]:
            cnt += 1
    print(min(n - 1, cnt + k * 2))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 39536
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, M, C; cin >> N >> M >> C;
	vector<int> B(M, 0);
	rep (i, M){
		cin >> B[i];
	} // end rep
	vector<vector<int> > A(N, vector<int>(M, 0));
	rep (i, N){
		rep (j, M){
			cin >> A[i][j];
		} // end rep
	} // end rep

	int res = 0;
	rep (i, N){
		int curr = 0;
		rep (j, M){
			curr += A[i][j] * B[j];
		} // end rep
		curr += C;
		res += (int)(curr > 0);
	} // end rep

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>//懒人专用头文件
using namespace std;
char a[101],b[101];
bool cmp(char a,char b){return a>b;}
bool jg(){
    int minn=min(strlen(a),strlen(b));
    for(register int i=0;i<minn;i++)
    {
		if(a[i]==b[i])continue;
        if(a[i]<b[i])return 1;
        else return 0;
	}
    if(strlen(a)<strlen(b))return 1;
    else return 0;
}
main()
{
	gets(a);gets(b);
	sort(a,a+strlen(a));sort(b,b+strlen(b),cmp);
	if(jg())puts("Yes");
	else puts("No");
}/**/

Measured memory_bytes: 256
coin_500=int(input())
coin_100=int(input())
coin_50=int(input())
x=int(input())
ans=0
for i in range(coin_500+1):
    for j in range(coin_100+1):
        for k in range(coin_50+1):
            if i*500+j*100+50*k==x:
                ans+=1
print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
	string s;
	int n, r = 0, b = 0;
	cin >> n >> s;
	for(int i = 0; i < n; i++){
		if(s[i] == 'R')r++;
		else b++;
	}
	if(r > b)cout <<"Yes";
	else cout<<"No";
return 0;
}


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

main()
{
    int n, p;
    while (cin >> n)
    {
        if (n == 0)
            return 0;
        for (int i = 0; i < 9; i++)
        {
            cin >> p;
            n -= p;
        }
        cout << n << endl;
    }
}


Measured memory_bytes: 3100
#define  _USE_MATH_DEFINES
#define  _USE_MATH_DEFINES

#define  rep(i, n) for(int i = 0; i < n; i++)
#define  repx(i, a, n) for(int i = a; i < n; i++)
#define  loop while(1)
#define  lli long long int
#define  aryout(ary) rep(i, ary.size()) cout << ary[i] << (i < ary.size() - 1 ? " " : "\n");
 
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <utility>
#include <set>

using namespace std;

vector<int> subset_sum_total(vector<int> v) {
  
  int n = v.size();
  int sum = accumulate(v.begin(), v.end(), 0);

  vector<int> tab1(sum + 1, 0);
  tab1[0] = 1;

  rep(i, n) {
    for (int j = sum - v[i]; j >= 0; j--) 
      tab1[j + v[i]] += tab1[j];
  }
  return tab1;
}

int main() {

  int n;
  cin >> n;

  vector<int> v(n);
  rep(i, n) cin >> v[i];
  vector<int> ans = subset_sum_total(v);

  int m;
  cin >> m;

  int q;
  rep(i, m) {
    cin >> q;
    if (q < ans.size() && ans[q] > 0)
      cout << "yes" << endl;
    else
      cout << "no" << endl;
  }

  return 0;
}



Measured memory_bytes: 3156
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from collections import defaultdict


def main():
    n = int(input().strip())

    diff_a = defaultdict(int)
    diff_b = defaultdict(int)
    for _ in range(n):
        a, b = map(int, input().split())
        diff_a[a] += 1
        diff_b[b] += 1

    cur = 0
    for i in sorted(diff_a):
        cur += diff_a[i]
        if cur >= n // 2 + 1:
            b1 = i
            break
    cur = 0
    for i in sorted(diff_b, reverse=True):
        cur += diff_b[i]
        if cur >= n // 2 + 1:
            e1 = i
            break

    if n % 2 == 1:
        print(e1 - b1 + 1)
        return

    cur = 0
    for i in sorted(diff_a):
        cur += diff_a[i]
        if cur >= n // 2:
            b2 = i
            break
    cur = 0
    for i in sorted(diff_b, reverse=True):
        cur += diff_b[i]
        if cur >= n // 2:
            e2 = i
            break
    ans = e2 + e1 - (b1 + b2) + 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 45980
#include<stdio.h>
#define N 100

int cnt=0;
int a[N];

void swap(int x,int y){
	int temp=a[x];
	a[x]=a[y];
	a[y]=temp;
	return;
}

void selectionSort(int n){
	int i,j;
	int min;
	int idx;
	
	for(i=0;i<n;i++){
		min=1000;
		for(j=i+1;j<n;j++){
			if(min > a[j]){
				idx=j;
				min=a[j];
			}
		}
		if(a[i] > min){
			swap(i,idx);
			cnt++;
		}
	}
	
	return;
}

int main(){
	int n,i;
	
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	
	selectionSort(n);
	
	for(i=0;i<n-1;i++)
		printf("%d ",a[i]);
	printf("%d\n",a[n-1]);
	
	printf("%d\n",cnt);
	
	return 0;
	
}


Measured memory_bytes: 2144