akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int N=20,M=524288,mo=1e9+7;

typedef long long LL;

int n,m,K,lim[N][N],g[M],f[2][M],p,q,nxt[N][M],h[N][M],ans,T;

int main()
{
	scanf("%d%d%d",&n,&m,&K); T=1<<n-1;
	memset(lim,255,sizeof(lim));
	for (int a,b;K--;scanf("%d",&lim[a-1][b-1])) scanf("%d%d",&a,&b);
	for (int i=1,j,k,la;i<M;i++)
	{
		for (j=T>>1,k=n-2,la=0;k>=0;k--,j>>=1)
		{
			nxt[k][i]=la;
			if (j&i) la=j;
		}
		//for (k=0,j=1,la=0;k<n-1;k++,j<<=1) cnt[k][i]=la+=((j&i)>0);
	}
	g[0]=1;
	for (int i=0,j,k,st;i<m;i++)
	{
		p=0; q=1;
		memcpy(f[0],g,sizeof(g));
		memset(h,0,sizeof(h));
		for (j=0,k=1;j<n-1;j++,p^=1,q^=1,k<<=1)
		{
			memset(f[q],0,sizeof(f[q]));
			for (st=0;st<T;st++) if (f[p][st]>0)
			{
				if (lim[i][j]==-1)
				{
					f[q][st]=(f[q][st]+f[p][st])%mo;
					if (!(k&st))
					{
						if (!nxt[j][st]) h[j+1][st|k]=(h[j+1][st|k]+f[p][st])%mo;
						else f[q][(st|k)^nxt[j][st]]=(f[q][(st|k)^nxt[j][st]]+f[p][st])%mo;
					}
				}else if (lim[i][j]==0)
				{
					if ((k&st)) continue;
					f[q][st]=(f[q][st]+f[p][st])%mo;
				}else
				{
					if ((k&st))
					{
						f[q][st]=(f[q][st]+f[p][st])%mo;
					}else
					{
						if (!nxt[j][st]) h[j+1][st|k]=(h[j+1][st|k]+f[p][st])%mo;
						else f[q][(st|k)^nxt[j][st]]=(f[q][(st|k)^nxt[j][st]]+f[p][st])%mo;
					}
				}
			}
		}
		for (j=2,k=2;j<n;j++,k<<=1)
		{
			for (st=0;st<k;st++) if (h[j-1][st]>0)
			{
				if (lim[i][j-1]!=1) h[j][st]=(h[j][st]+h[j-1][st])%mo;
				if (lim[i][j-1]!=0) h[j][st|k]=(h[j][st|k]+h[j-1][st])%mo;
			}
		}
		for (st=0;st<T;st++) g[st]=(f[p][st]+h[n-1][st])%mo;
	}
	ans=0;
	for (int st=0;st<T;st++) ans=(ans+g[st])%mo;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 88192
from collections import defaultdict
N, A = map(int, input().split())
X = list(map(int, input().split()))

dp = defaultdict(dict)
dp[0][0] = 1  # カード0枚で合計

for x in X:
    newDP = defaultdict(dict)
    for card, memo in dp.items():
        for k, v in memo.items():
            # カードXを追加しない
            if k in newDP[card]:
                newDP[card][k] += v
            else:
                newDP[card][k] = v
            # カードXを追加するよ
            if k + x in newDP[card + 1]:
                newDP[card + 1][k + x] += v
            else:
                newDP[card + 1][k + x] = v
    dp = newDP

ans = 0
for i in range(1, N + 1):
    if A * i in dp[i]:
        ans += dp[i][A * i]
print(ans)

Measured memory_bytes: 7524
#include<iostream>
#include<vector>
#include<map>
#include<cmath>
#include<algorithm>
#include<string>
#include<set>
#include<deque>
#include<bits/stdc++.h>

using namespace std;

#define pb push_back
#define ld long double
#define int long long

mt19937 rnd(51);

const int MOD = 1e9 + 7;
const int N = 2e5 + 10;

int t[4 * N];

void update(int v, int l, int r, int pos, int val){
    if (l == r){
        t[v] = val;
        return;
    }
    int m = (l + r) / 2;
    if (pos <= m){
        update(2 * v, l, m, pos, val);
    }
    else{
        update(2 * v + 1, m + 1, r, pos, val);
    }
    t[v] = min(t[v * 2], t[v * 2 + 1]);
}

int get(int v, int tl, int tr, int l, int r){
    if (l > r) return 1e18;
    if (tl == l && tr == r){
        return t[v];
    }
    int tm = (tl + tr) / 2;
    return min(get(2 * v, tl, tm, l, min(r, tm)), get(2 * v + 1, tm + 1, tr, max(l, tm + 1), r));
}

void update1(int v, int l, int r, int pos, int val){
    if (l == r){
        t[v] = val;
        return;
    }
    int m = (l + r) / 2;
    if (pos <= m){
        update1(v * 2, l, m, pos, val);
    }
    else{
        update1(v * 2 + 1, m + 1, r, pos, val);
    }
    t[v] = max(t[v * 2], t[v * 2 + 1]);
}

int get1(int v, int tl, int tr, int l, int r){
    if (l > r) return -1e18;
    if (tl == l && tr == r) return t[v];
    int tm = (tl + tr) / 2;
    return max(get1(2 * v, tl, tm, l, min(r, tm)), get1(2 * v + 1, tm + 1, tr, max(l, tm + 1), r));
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    map<pair<int,int>, int> ind;
    vector<pair<int,int>> v(n), a;
    vector<pair<int, pair<int,int>>> b;
    for (int i = 0; i < n; i++){
        cin >> v[i].first >> v[i].second;
        ind[{v[i].first, v[i].second}]++;
        a.pb({v[i].second, v[i].first});
    }
    int ans = 0;
    sort(a.begin(), a.end());
    int now = 0;
    for (auto to : a){
        ind[{to.second, to.first}] = now++;
        update(1, 0, n - 1, now - 1, to.second + to.first);
        b.pb({to.second, {to.first, now - 1}});
    }
    sort(b.rbegin(), b.rend());
    for (int i = 0; i < n; i++){
        update(1, 0, n - 1, b[i].second.second, 1e18);
        int l = -1, r = n;
        while(r - l > 1){
            int mid = (r + l) / 2;
            if (b[i].second.first >= a[mid].first){
                l = mid;
            }
            else{
                r = mid;
            }
        }
        ans = max(ans, b[i].first + b[i].second.first - get(1, 0, n - 1, 0, l));
    }
    for (int i = 0; i < n; i++){
        update1(1, 0, n - 1, b[i].second.second, b[i].second.first + (b[0].first - b[i].first));
    }
    for (int i = 0; i < n; i++){
        update1(1, 0, n - 1, b[i].second.second, -1e18);
        int l = -1, r = n;
        while(r - l > 1){
            int mid = (r + l) / 2;
            if (a[mid].first >= b[i].second.first){
                r = mid;
            }
            else{
                l = mid;
            }
        }
        ans = max(ans, get1(1, 0, n - 1, r, n - 1) - (b[0].first - b[i].first) - b[i].second.first);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 33876
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

bool used[1000010];
std::vector<ll> primes;

void sieve( ll n ) {
  used[0] = used[1] = true;

  for( ll i = 2; i*i <= n; ++i ) {
    if( used[i] )
      continue;

    primes.emplace_back( i );

    for( ll j = i; j <= n; j += i )
      used[j] = true;
  }

  return;
}

ll N;

int main()
{
  std::cin >> N;

  sieve( 1000010 );

  ll cnt2 = 0, cnt4 = 0, cnt14 = 0, cnt24 = 0, cnt74 = 0;

  for( auto p : primes ) {
    ll n = N, e = 0;
    
    while( n > 0 ) {
      e += n/p;
      n /= p;
    }

    if( e >= 74 ) {
      ++cnt74;
    }
    if( e >= 24 ) {
      ++cnt24;
    }
    if( e >= 14 ) {
      ++cnt14;
    }
    if( e >= 4 ) {
      ++cnt4;
    }
    if( e >= 2 ) {
      ++cnt2;
    }
  }

  auto comb = [&]( ll cS, ll cL ) {
    return (cS-cL)*cL*(cL-1)/2+cL*(cL-1)*(cL-2)/2;
  };

  auto count = [&]( ll cS, ll cL ) {
    return (cS-cL)*cL+cL*(cL-1);
  };

  ll ans = comb( cnt2, cnt4 );
  ans += count( cnt4, cnt14 );
  ans += count( cnt2, cnt24 );
  ans += cnt74;

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 1280
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};



int A, B;

int main () {
  cin >> A;
  cin >> B;

  int ans;
  if (A == 1 && B == 2) {
    ans = 3;
  } else if (A==1&&B==3) {
    ans = 2;
  } else if (A==2&&B==1) {
    ans = 3;
  } else if (A==2&&B==3) {
    ans = 1;
  } else if (A==3&&B==1) {
    ans = 2;
  } else {
    ans = 1;
  }

  cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>

int main(){
    std::string inp;
    std::cin >> inp;
    for(int i = 0; i < inp.length(); i++){
        if(i%2 == 0 && inp[i] == 'L'){
            std::cout << "No";
            return 0;
        }
        else if(i%2 == 1 && inp[i] == 'R'){
            std::cout << "No";
            return 0;
        }
    }
    std::cout << "Yes";
    return 0;
}

Measured memory_bytes: 256
import java.io.{BufferedReader, InputStream, InputStreamReader, PrintWriter}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.reflect.ClassTag

object Main {
  val MOD = 1000000007
  val out = new PrintWriter(System.out)
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N, M = sc.nextInt()
    val uf = new UnionFind(N + M)
    rep(N) { i =>
      val k = sc.nextInt()
      rep(k) { _=>
        val l = sc.nextInt() - 1
        uf.unite(i, N + l)
      }
    }

    val ok = (0 until N - 1) forall (i => uf.find(i) == uf.find(i + 1))
    val ans = if(ok) "YES" else "NO"
    out.println(ans)
  }


  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextLong(): Long = next.toLong
    def nextChar(): Char = next.charAt(0)
  }

  private def rep(n: Int)(f: Int => Unit): Unit = (0 until n) foreach f

  private def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    (0 until n) foreach (i => res(i) = f(i))
    res
  }

  private implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(a => map.getOrElseUpdate(f(a), ArrayBuffer()) += a)
      map
    }

    def rep(f: A => Unit): Unit = {
      as.indices foreach (i => f(as(i)))
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(a => sum = num.plus(sum, f(a)))
      sum
    }
  }

  private implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }

  class UnionFind(n: Int) {
    private val par = Array.ofDim[Int](n)
    par.indices foreach (i => par(i) = i)
    private val rank = Array.ofDim[Int](n)

    def find(x: Int): Int = {
      val stack = ListBuffer[Int]()
      def step(x: Int): Int = {
        if (par(x) == x) x
        else {
          stack += x
          step(par(x))
        }
      }

      val res = step(x)
      stack foreach (i => par(i) = res)
      res
    }

    def unite(x: Int, y: Int): Unit = {
      val x1 = find(x)
      val y1 = find(y)
      if (x1 != y1) {
        if (rank(x1) < rank(y)) {
          par(x1) = y1
        } else {
          par(y1) = x1
          if (rank(x1) == rank(y1)) rank(x1) += 1
        }
      }
    }
  }
}


Measured memory_bytes: 54724
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;
#define rep(i,n) for(int i=0;i<(n);i++)

int main() {
  int n;
  cin >> n;
  ll p = 1;
  rep(i,n) {
    p = p * (i+1) % 1000000007;
  }
  cout << p << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int dp[2][11000];
int d[600];
int e[600];
int f[600];
int g[600];
int w[1100];
pair<int,pair<int,int> > ev[1100];
int c;
int calc(){
	int ret=1010101010;
	int las=-1010101010;
	for(int i=0;i<=c;i++){
		if(~dp[0][i])las=i;
		if(~dp[1][i])ret=min(ret,i-las);
	}
	las=-1010101010;
	for(int i=0;i<=c;i++){
		if(~dp[1][i])las=i;
		if(~dp[0][i])ret=min(ret,i-las);
	}
	return ret;
}
int main(){
	int a,b;
	scanf("%d%d%d",&a,&b,&c);
	for(int i=0;i<a;i++)scanf("%d%d",d+i,e+i);
	for(int i=0;i<b;i++)scanf("%d%d",f+i,g+i);
	int n=0;
	for(int i=0;i<a;i++)ev[n++]=make_pair(e[i],make_pair(0,i));
	for(int i=0;i<b;i++)ev[n++]=make_pair(g[i],make_pair(1,i));
	std::sort(ev,ev+n);
	for(int i=0;i<n;i++){
		if(ev[i].second.first)w[i]=f[ev[i].second.second];
		else w[i]=d[ev[i].second.second];
	}
	int ret=1010101010;
	for(int i=0;i<11000;i++)dp[0][i]=dp[1][i]=-1;
	int L=0;
	int C=1010101010;
	int M=1010101010;
	for(int i=0;i<n;i++){
		int t=ev[i].second.first;
		
		for(int j=c;j>=0;j--){
			if(~dp[t][j]&&j+w[i]<=c)dp[t][j+w[i]]=max(dp[t][j+w[i]],dp[t][j]);
		}
		if(w[i]<=c)dp[t][w[i]]=max(dp[t][w[i]],i);
		int dis=calc();
		C=ev[i].first-ev[L].first;
	//	printf("%d %d: %d %d\n",L,i,C,dis);
		ret=min(ret,max(C,dis));
		while(L<i&&dis<C){
			for(int j=0;j<=c;j++){
				if(dp[0][j]==L)dp[0][j]=-1;
				if(dp[1][j]==L)dp[1][j]=-1;
			}
			L++;
			dis=calc();
			C=ev[i].first-ev[L].first;
//			printf("%d %d: %d %d\n",L,i,C,dis);
			ret=min(ret,max(C,dis));
		}
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 1140
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] ds = new int[K];
        for (int i = 0; i < K; i++) {
            ds[i] = sc.nextInt();
        }
        System.out.println( solve(N, ds) );
    }

    private static int solve(int N, int[] ds) {
        Set<Integer> hateDigits = new HashSet<>();
        for (int d : ds) {
            hateDigits.add(d);
        }

        int n = N;
        while(true) {
            // 答えがせいぜい6桁, isOkが10回ほどなので
            // O(六桁 * isOk) = O(10^6)で時間内に収まるはず
            if( isOk(n, hateDigits) ) {
                return n;
            } else {
                n++;
            }
        }
    }

    private static boolean isOk(int n, Set<Integer> hateDigits) {
        String s = String.valueOf(n);
        for (int i = 0; i < s.length(); i++) {
            if( hateDigits.contains( s.charAt(i) - '0' ) ) {
                return false;
            }
        }
        return true;
    }
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<string> a(n), b(m);
  for (auto &&w : a) {
    cin >> w;
  }
  for (auto &&w : b) {
    cin >> w;
  }
  for (int i = 0; i <= n - m; i++) {
    for (int j = 0; j <= n - m; j++) {
      bool same = true;
      for (int k = 0; k < m; k++) {
        for (size_t l = 0; l < m; l++) {
          if (a[k + i][l + j] != b[k][l]) same = false;
        }
      }
      if (same) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<string>
#include<cstdio>
#include<stack>
#include<memory.h>
#include<cmath>
#include<bitset>
#include<functional>
#include<memory>
#include<utility>
using namespace std;
#define FOR(i,m,n) for(i=m;i<n;i++)
#define MIN(x,y) (x>y?y:x)
#define ab(x,y) (x>y ?(x-y):(y-x))
#define CLR(a,b) memset(a,b,sizeof(a))
#define ROF(i,m,n) for(i=m;i>=n;i--)
#define BUG cout<<"debug"<<endl;
#define RT return
#define BK break
#define HEAP priority_queue
#define SP " "
#define lowf(a,b,c) lower_bound(a,b,c)
#define upf(a,b,c) upper_bound(a,b,c)
#define CP bool cmp(node A,node B)
#define maxn 100000
typedef long long LL;
typedef vector<int> VI;
const int INF = 2147483647;
const int NEN = -INF - 1;
const LL LINF = 9223372036854775807;
int fa[maxn+5];
int node[maxn + 5];
int N, Q;
int main()
{
	while (1)
	{
		memset(node, 0, sizeof(node));
		scanf("%d%d", &N, &Q);
		if (N == 0 && Q == 0)break;
		int i;
		LL sum = 0;
		char ope;
		int  a;
		FOR(i, 1, N)
		{
			scanf("%d", &fa[i + 1]);
		}
		node[1] = 1;
		while (Q--)
		{
			scanf("%c", &ope);
			scanf("%c", &ope);
			scanf("%d", &a);
			if (ope == 'M')node[a] = 1;
			else
			{
				while (node[a] != 1)
				{
					a = fa[a];
				}
				sum += a;
			}
		}
		cout << sum << endl;
	}
}


Measured memory_bytes: 3936
#include "bits/stdc++.h"
using namespace std;

int main(void){

  int N;
  cin >> N;

  vector<int> Y(N);
  for (int i = 0; i < N; i++) cin >> Y.at(i);

  int Ymin = Y.at(0);
  int K = Y.at(1) - Y.at(0);
  for (int i = 1; i < N; i++)
  {
    /*if ((Y.at(i) - Ymin) > K)
    {
      K = (Y.at(i) - Ymin);
    }
    if (Y.at(i) < Ymin)
    {
      Ymin = Y.at(i);
    }*/

    K = max((Y.at(i)-Ymin), K);
    Ymin = min(Y.at(i), Ymin);
    
  }
  
  cout << K << endl;
  


  return 0;

}



Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
const int N = 200010;
int n, k,f,r;
string s;
char q[N*10];
char oppo(char ch)
{
	return 'A' + ((ch - 'A') ^ 1);
}
char show(int c, char ch)
{
	if (!c) return ch;
	else return oppo(ch);
}
int main()
{
	cin >> n >> k >> s;
	int c = 0, step = 0;
	for (int i = 0; i < n; i++)
	{
		if (c == s[i] - 'A') step += 2; else step++;
		c = c ^ 1;
	}
	if (k > step) k = (k - step) % n + step;
	c = 0; f = 0; r = n;
	for (int i = 0;i < n;i++) q[i] = s[i];
	while (k--)
	{
		if (show(c, q[f]) == 'A') q[f] = oppo(q[f]);
		else {
			c ^= 1;
			f++;
			q[r++] = show(c, 'A');
		}
	}
	if (c) for (int i = f; i < r; i++) q[i] = oppo(q[i]);
	for (int i = f;i < r;i++) printf("%c",q[i]);
	return 0;
}


Measured memory_bytes: 1284
import sys
input = sys.stdin.buffer.readline

def main():
    N,A,B = map(int,input().split())
    if A == B:
        print(1)
    elif A > B:
        print(0)
    else:
        if N == 1:
            print(0)
        elif N == 2:
            print(1)
        else:
            print(((N-1)*B+A)-((N-1)*A+B)+1)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    int n,sum=0;
    cin >> n;
    int s[n];
    for(int i=0;i<n;i++){
        cin >> s[i];
        sum += s[i];
    }
    if(sum % 10 != 0){
        cout << sum << endl;
        return 0;
    }
    sort(s,s+n);
    bool flg=false;
    for(int i=0;i<n;i++){
        if(s[i] % 10 != 0){
            sum -= s[i];
            flg=true;
            break;
        }
    }
    if(flg) cout << sum << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int H,N,sum=0;
  cin>>H>>N;
  vector<int> A(N,0);
  for(int i=0;i<N;i++)
  {
    cin>>A.at(i);
    sum+=A.at(i);
  }
  H<=sum?cout<<"Yes"<<endl:cout<<"No"<<endl;
}

Measured memory_bytes: 640
/**
 * Created by karayuu on 2019/06/17
 */
fun main(args: Array<String>) {
    val (a, b) = readLine()!!.split(" ")
    if (a == "H") {
        println(b)
    } else {
        if (b == "H") {
            println("D")
        } else {
            println("H")
        }
    }
}


Measured memory_bytes: 35960
#include<cstdio>

int main(){
    int d_1,a_1,d_2,a_2;
    scanf("%d %d %d %d", &d_1, &a_1, &d_2, &a_2);
    int taka,aoki;
    taka = (d_2-1)/a_1 + 1;
    aoki = (d_1-1)/a_2 + 1;
    if (taka<=aoki) printf("Yes");
    else printf("No");
    return 0;
}

Measured memory_bytes: 1736
def countingSort(A):
    k = max(A)
    B = [0]
    B.extend(A)
    C = []
    n = len(A)
    for i in range(k + 1):
        C.append(0)

    for j in range(0, n):
        C[A[j]] += 1
    
    for i in range(1, k + 1):
        C[i] += C[i - 1]
    
    for j in range(n - 1, -1, -1):
        B[C[A[j]]] = A[j]
        C[A[j]] -= 1
    print(' '.join(list(map(str, B[1:]))))
    return
N = int(input())
a = list(map(int, input().split()))
countingSort(a)


Measured memory_bytes: 251212
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N; i >= 0; i--)
const ll INF = 1000000007;
#define PI 3.1415926535
using Graph = vector<vector<int>>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true;} return false;}
bool seen[100000];
void dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする
 
    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}
 
//dpTable
int dp[100050];
int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    ll cnt = 0;
    int hoge = 0;
    rep (i,N) {
        cin >> A.at(i);
        if (A.at(i) < 0) {
            hoge++;
            A.at(i) *= -1;
        }
        cnt += A.at(i);
    }
    if (hoge % 2 == 1) {
        sort(A.begin(),A.end());
        cnt -= A.at(0) * 2;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3984
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop
import numpy as np

INF = float('inf')
NIL = - 1

N = int(input())
arr = np.arange(N + 1, dtype=np.int64)
arr[::3] = 0
arr[::5] = 0
print(sum(arr))


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

int main(){
  int N;
  cin >> N;
  ll a[N];
  for(int i=0;i<N;i++) cin >> a[i];
  ll sum[N+1];
  sum[0] = 0LL;
  for(int i=1;i<=N;i++) sum[i] = sum[i-1] + a[i-1];

  ll ans = 1000000000000000;
  for(int i=0;i<N-1;i++){
    ll x,y;
    x = sum[i+1];
    y = sum[N] - sum[i+1];
    ans = min(ans, abs(x-y));
  }

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


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
const int maxn=100+10;
int n,arr[maxn],cnt=0;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++) cin>>arr[i];
    bool flag=1;
    for(int i=0;flag;i++){
        flag=0;
        for(int j=n-1;j>i;j--){
            if(arr[j-1]>arr[j]){
                flag=1;
                swap(arr[j],arr[j-1]);
                cnt++;
            }
        }
    }
    for(int i=0;i<n;i++){
        if(i) cout<<" ";
        cout<<arr[i];
    }
    cout<<"\n"<<cnt<<"\n";
    return 0;
}
/*
#include<bits/stdc++.h>
using namespace std;
const int maxn=100+10;
int n,arr[maxn];
int main()
{
    cin>>n;
    for(int i=0;i<n;i++) cin>>arr[i];
    for(int i=0;i<n;i++){
        int v=arr[i];
        int j=i-1;
        while(j>=0&&arr[j]>v){
            arr[j+1]=arr[j];
            j--;
        }
        arr[j+1]=v;
        for(int i=0;i<n;i++){
            if(i) cout<<" "<<arr[i];
            else cout<<arr[i];
        }cout<<"\n";
    }
    return 0;
}
*/



Measured memory_bytes: 3124
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

vector<int> Divisors(int n) {
	vector<int> res;
	for(int i = 1; i * i <= n; ++i) {
		if( n % i == 0 ) {
			res.push_back(i);
			res.push_back(n / i);
		}
	}
	
	sort(res.begin(), res.end());
	
	return res;
}

int main(void) {
	int a, b, k;
	cin >> a >> b >> k;
	
	vector<int> adiv = Divisors(a);
	vector<int> bdiv = Divisors(b);
	vector<int> div = adiv;
	
	for(auto x : bdiv) {
		div.push_back(x);
	}
	
	sort(div.begin(), div.end());
	div.erase(unique(div.begin(), div.end()), div.end());
	
	vector<int> tdiv;
	
	for(auto x : div) {
		if( x <= min(a, b) && a % x == 0 && b % x == 0 ) {
			tdiv.push_back(x);
		}
	}
	
	int n = tdiv.size();
	cout << tdiv[n - k] << endl;
	
	return 0;
}


Measured memory_bytes: 256
r, c = map(int, input().split())
a = []

for i in range(r):
    a.append(list(map(int, input().split())))
    a[i].append(sum(a[i]))

for i in range(r):
    print(" ".join(list(map(str, a[i]))))

col_sum = []
for j in range(c+1):
    su = 0
    for i in range(r):
        su += a[i][j]
    col_sum.append(su)

print(" ".join(list(map(str, col_sum))))




Measured memory_bytes: 5700
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
using namespace std;
#define INF 100000
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

ll S[210000];
int N;
ll K,A[210000],F[210000],sum=0;


bool check(ll x){
    ll count=0;
    for(int i=0;i<N;i++){
        if(A[i]-x/F[i]<0) continue;
        count+=(A[i]-x/F[i]);
        if(count>K) return false;
    }
    return true;
}

int main(){
    cin>>N>>K;
    for(int i=0;i<N;i++){
        cin>>A[i];
        sum+=A[i];
    } 
    if(sum<=K){
        cout<<0<<endl;
        return 0;
    }
    for(int i=0;i<N;i++) cin>>F[i];
    sort(A,A+N,greater<ll>());
    sort(F,F+N);
    for(int i=0;i<N;i++) S[i]=A[i]*F[i];

  ll ng=0,ok=10000000000000;
  while(ok-ng!=1){
    ll mid=(ng+ok)/2;
    if(check(mid)) ok=mid;
    else ng=mid;
  }
  cout<<ok<<endl;

}



Measured memory_bytes: 4992
#include<algorithm>
#include<cstdio>
#include<map>
#include<cstring>
using namespace std;
int n;
int a[200005];
map<int,int>mp;
int main()
{
    scanf("%d",&n);
    int s=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if(mp[a[i]]==1)
        {
            s=1;
        }
        else
        {
            mp[a[i]]++;
        }
    }
    if(s)
    {
        printf("NO");
    }
    else
    {
        printf("YES");
    }

}

Measured memory_bytes: 10368
#include<stdio.h>
int main(void)
{
 char num[1001];
 int i = 0;
 int sum = 1;  
	while(sum!=0){
	sum=0;
	i=0;
 scanf("%c",&num[i]);  
while(num[i] != '\n'){
  i++;
  scanf("%c",&num[i]);
 }  
num[i] = '\0';    
i = 0;
 while(num[i] != '\0'){
  sum += num[i] - '0';
  i++;
 }
 if(sum!=0){
 printf("%d\n",sum);
 }
 }
 return 0;
}

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

int main(){
  int N, K;
  cin >> N >>K;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  
  int answer=0;
  for(int i=0; i<N; i++){
    if(vec.at(i)>=K){
      answer++;
    }
  }
  
  cout <<answer<<endl;
  return 0;
}

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

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

    bool isPossible = true;
    int prevHeight;
    cin >> prevHeight;
    for (int i = 1; i < n; ++i)
    {
        int input;
        cin >> input;

        if (input < prevHeight - 1)
        {
            isPossible = false;
            break;
        }
        else if (input == prevHeight - 1)
        {
            ++input;
        }

        prevHeight = input;
    }

    cout << (isPossible ? "Yes" : "No") << endl;
}

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

signed main(){
  
  int q;
  cin>>q;
  
  while( q-- ){
    
    int a, b;
    cin>>a>>b;
    
    if( a > b ) swap( a, b );
    
    double x = sqrt( (double)a * b - 1 );
    
    int l = x;

    int r = ( (double)a * b - 1 ) / l;
    
    int ans = l * 2;
    
    if( l == r ) ans--;
    
    if( a <= l ) ans--;
    
    cout<<ans<<endl;
    
  }
    
  return 0;
}


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

#define mp make_pair
#define pb push_back

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int MAX_N = 2000;
int n;
int x[2*MAX_N];
char col[2*MAX_N];
int bc[2*MAX_N][MAX_N+1];
int wc[2*MAX_N][MAX_N+1];
int dp[MAX_N+1][MAX_N+1];
int rb[MAX_N+1];
int rw[MAX_N+1];

int main()
{
  cin >> n;
  for (int i = 0; i < 2*n; ++i) {
    cin >> col[i] >> x[i];
    if (col[i] == 'B') {
      rb[x[i]] = i;
    } else {
      rw[x[i]] = i;
    }
  }

  for (int i = 0; i <= n; i++) {
    int w = 0, b = 0;
    for (int j = 0; j < 2*n; j++) {
      if (x[j] > i) {
        if (col[j] == 'B') b++;
        else w++;
      }
      bc[j][i] = b;
      wc[j][i] = w;
    }
  }

  dp[0][0] = 0;
  for (int j = 1; j <= n; j++)
    dp[0][j] = dp[0][j-1] + wc[rw[j]][j] + bc[rw[j]][0];
  for (int i = 1; i <= n; i++)
    dp[i][0] = dp[i-1][0] + bc[rb[i]][i] + wc[rb[i]][0];

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      dp[i][j] = min(dp[i-1][j] + (bc[rb[i]][i] + wc[rb[i]][j]),
                     dp[i][j-1] + (wc[rw[j]][j] + bc[rw[j]][i]));
    }
  }

  cout << dp[n][n] << endl;

  return 0;
}


Measured memory_bytes: 78464
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;
NodePointer nil;

NodePointer listSearch(int key){
  NodePointer n;
  for( n = nil->next; n != nil; n = n->next ){
	  if( n->key == key ) return n;
  }
  return '\0'; //returns NULL when not found
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}
void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
	  t->next->prev = t->prev;
	  t->prev->next = t->next;
}

void deleteFirst(){
  NodePointer f;
  if ( (f=nil->next) == nil ) return;
  deleteNode(f);
}

void deleteLast(){
  NodePointer l;
  if( (l=nil->prev) == nil ) return;
  deleteNode(l);
}

void delete(int key){
  NodePointer n;
  n = listSearch(key);
  if( n != '\0' ){
	  deleteNode(n);
  }
}
void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++;
      }
      size--;
    }
  }
  printList();
  return 0;
}

Measured memory_bytes: 34976
#include<stdio.h>
#include<string.h>
int main()
{
	int n,i,j,a=0,b=0,c;
	char s[100];
	scanf("%d %s",&n,s);
	b=strlen(s);
	if(n%2!=0) printf("No\n");
	else{
		c=b/2;
		for(i=0;i<c;i++){
			if(s[i]==s[i+c]) a++;
		}
		if(n/2==a) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}


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

int main(){
    int n; cin >> n;
    int cnt = 0;
    string S; cin >> S;
    //cout << S;
    string subS1, subS2, subS3;
    int idx1, idx2, idx3;
    for(int i = 0; i < 10; i++){
        string s1 = to_string(i);
        idx1 = S.find_first_of(s1);
        if(idx1 == string::npos) continue;
        subS1 = S.substr(idx1+1);
        for(int j = 0; j < 10; j++){
            string s2 = to_string(j);
            idx2 = subS1.find_first_of(s2);
            if(idx2 == string::npos) continue;
            subS2 = subS1.substr(idx2+1);
            
            for(int k = 0; k < 10; k++){
                string s3 = to_string(k);
                idx3 = subS2.find_first_of(s3);
                if(idx3 == string::npos) continue;
                else cnt++;
            }
        }
    }
    cout << cnt << endl;;
}

Measured memory_bytes: 508
import sys

input = sys.stdin.readline
sys.setrecursionlimit(100000)


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


def read_index():
    return map(lambda x: int(x) - 1, input().split())


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v

    def __str__(self):
        return str(self.v)

    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n)


class LCA:
    def __init__(self, N, L):
        self.L = L
        self.INF = (N, None)
        self.M0 = 2 ** (2 * N - 1).bit_length()
        self.data = [self.INF] * (2 * self.M0)
        self.D = [0] * N
        self.F = [0] * N
        self.S = []
        self.dist = [0] * N

        self.dfs1(0, 0, -1)
        for i, v in enumerate(self.S):
            self.data[self.M0 - 1 + i] = (self.D[v], i)
        for i in range(self.M0 - 2, -1, -1):
            self.data[i] = min(self.data[2 * i + 1], self.data[2 * i + 2])

    def dfs1(self, v, d, p, pd=0):
        self.F[v] = len(self.S)
        self.D[v] = d
        self.S.append(v)
        self.dist[v] = pd
        for w, c, dis in self.L[v]:
            if w == p:
                continue
            self.dfs1(w, d + 1, v, pd + dis)
            self.S.append(v)

    def _query(self, a, b):
        yield self.INF
        a += self.M0
        b += self.M0
        while a < b:
            if b & 1:
                b -= 1
                yield self.data[b - 1]
            if a & 1:
                yield self.data[a - 1]
                a += 1
            a >>= 1
            b >>= 1

    def query(self, u, v):
        fu = self.F[u]
        fv = self.F[v]
        if fu > fv:
            fu, fv = fv, fu
        return self.S[min(self._query(fu, fv + 1))[1]]

    def dist(self, v):
        return self.dist[v]


def dfs2(L, v, p, QS, ans, CC, CD):
    for q, x, y, f in QS[v]:
        ans[q] += (y * CC[x] - CD[x]) * f

    for w, c, dis in L[v]:
        if w == p:
            continue
        CC[c] += 1
        CD[c] += dis
        dfs2(L, w, v, QS, ans, CC, CD)
        CC[c] -= 1
        CD[c] -= dis


def main():
    N, Q = read_values()
    L = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b, c, d = read_values()
        a -= 1
        b -= 1
        c -= 1
        L[a].append((b, c, d))
        L[b].append((a, c, d))

    g = LCA(N, L)

    QS = [[] for _ in range(N)]
    ans = [0] * Q
    for q in range(Q):
        x, y, u, v = read_values()
        x -= 1
        u -= 1
        v -= 1
        w = g.query(u, v)
        ans[q] = g.dist[u] + g.dist[v] - 2 * g.dist[w]
        QS[u].append((q, x, y, 1))
        QS[v].append((q, x, y, 1))
        QS[w].append((q, x, y, -2))

    CC = [0] * N
    CD = [0] * N
    dfs2(L, 0, -1, QS, ans, CC, CD)

    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 212424
#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

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    int len = S.length();
    int ans = 0;
    int tmp = 0;
    string T;
    rep(i, len) {
        if (S[i] == 'A') T += 'A';
        else if (S[i] == 'B' && S[i + 1] == 'C') {
            T += 'X';
            i++;
        }
        else T += S[i];
    }
    len = T.length();
    //cout << T << endl;
    RREP(i, len - 1, 0) {
        if (T[i] == 'X') tmp++;
        else if (T[i] == 'A') ans += tmp;
        else tmp = 0;
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0)
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n, m;
lli a[100001];
vector<lli> e[100001];
bool visited[100001];
bool conned[100001];

lli dfs(lli v) {
  visited[v] = true;
  lli r = v;
  for (lli u : e[v]) {
    if (!visited[u]) {
      lli l = dfs(u);
      if (a[l] < a[r]) r = l;
    }
  }
  return r;
}

int main() {
  cin >> n >> m;
  read_n(a, n);
  for (lli i=0; i<m; ++i) {
    lli x, y; cin >> x >> y;
    e[x].push_back(y);
    e[y].push_back(x);
  }

  lli ans = 0, cnt = 0;
  for (lli v=0; v<n; ++v) {
    if (!visited[v]) {
      lli u = dfs(v);
      conned[u] = true;
      ans += a[u];
      ++cnt;
    }
  }

  if (cnt == 1) {
    cout << 0 << '\n';
    return 0;
  }
  if (2*cnt-2 > n) {
    cout << "Impossible\n";
    return 0;
  }

  vector<lli> ra;
  for (lli v=0; v<n; ++v) {
    if (!conned[v]) ra.push_back(a[v]);
  }

  sort(begin(ra), end(ra));

  for (lli i=0; i<cnt-2; ++i) ans += ra[i];

  cout << ans << '\n';
  return 0;
}


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

int main(){
    ll n,r,k;
    cin>>n>>r;
    if(n>=10){
        k=0;
    }else{
        k=1000-100*n;
    }
    cout<<r+k;
}

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

int main(){
  vector<vector<int>> a(3,(vector<int>(3,0)));
  REP(i,3) REP(j,3){
    cin>>a.at(i).at(j);
  }
  
  int n;cin>>n;
  REP(i,n){
    int tmp;cin>>tmp;
    REP(j,3) REP(k,3){
      if(a.at(j).at(k)==tmp) a.at(j).at(k)=0;
    }
  }
  
  bool f=0;
  REP(i,3){
    int sum=0;
    REP(j,3) sum+=a.at(i).at(j);
    if(!sum) f=1;
  }
  REP(i,3){
    int sum=0;
    REP(j,3) sum+=a.at(j).at(i);
    if(!sum) f=1;
  }
  if(!(a.at(0).at(0)+a.at(1).at(1)+a.at(2).at(2))) f=1;
  if(!(a.at(0).at(2)+a.at(1).at(1)+a.at(2).at(0))) f=1;  
   
  cout<<(f?"Yes":"No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll a,b;
    cin>>a>>b;
    if(6>a){
        cout<<0<<endl;
    }else if(a<13){
        cout<<b/2<<endl;
    }else{
        cout<<b<<endl;
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
#define EPS (1e-10)
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	string s,t; cin>>s; t="CODEFESTIVAL2016";
	int ans = 0;
	rep(i,16) if(s[i]!=t[i]) ans++;
	cout<<ans<<endl;
	return 0;
}


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

using int64 = long long;

int main()
{
    int N, K;
    std::cin >> N >> K;

    std::vector<int> X(N), Y(N);
    std::vector<int> sx(N), sy(N);
    for (int i = 0; i < N; i++) {
        std::cin >> X[i] >> Y[i];
        sx[i] = X[i];
        sy[i] = Y[i];
    }

    std::sort(sx.begin(), sx.end());
    std::sort(sy.begin(), sy.end());

    int64 min_area = LLONG_MAX;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            int xmin = sx[i], xmax = sx[j];
            for (int k = 0; k < N; k++) {
                for (int l = k + 1; l < N; l++) {
                    int ymin = sy[k], ymax = sy[l];

                    int in_count = 0;
                    for (int m = 0; m < N; m++) {
                        if (xmin <= X[m] && X[m] <= xmax &&
                            ymin <= Y[m] && Y[m] <= ymax) {
                            in_count++;
                        }
                    }

                    if (in_count >= K) {
                        min_area = std::min(min_area,
                                            (int64)(xmax - xmin) * (ymax - ymin));
                    }
                }
            }
        }
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define bye return 0
#define Yes cout << "Yes" << "\n"
#define No  cout << "No" << "\n"
#define YES cout << "YES" << "\n"
#define NO cout << "NO" << "\n"
using namespace std;
int main(){
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    vector<int> v;
    set<int> s;
    int t, a, b, c, cnt=0;
    string str;
    cin >> t;

    for(int i=1; i<=t; ++i){
    	if(i>9 && i<100){
    		continue;
    	}else if(i>999 && i<10000){
    		continue;
    	}else if(i>99999 && i<=1000000){
    		continue;
    	}else{
    	cnt++;
    	}
    }

    cout << cnt << "\n";

    
    

   bye;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
const ll MOD = 1e9 + 7;

void mainsolve(){

	ll k,n;
	cin >> n >> k;
	vector<ll> p(n);
	rep(i,n) cin >> p[i];

	vector<double> e(n);
	rep(i,n){
		double sum = p[i] * (p[i]+1) / 2;
		e[i] = sum / p[i];
	}

	vector<double> cume(n+1);
	rep(i,n) cume[i+1] =cume[i] + e[i];

	double res = 0;
	for(ll i = 0; i+k <= n; i++){
		double tmp = 0;
		tmp = cume[i+k] - cume[i];
		res = max(res, tmp);
	}

	printf("%.10f\n", res);
	return;
}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout<<#x<<"="<<x<<endl;
#define endl '\n'
#define M 1000000007
#define int long long
#define INF 1e18
#define N 1000005

using namespace std;

void solve()
{
    ll x;
    cin>>x;
    cout<<1-x<<endl;
}

int32_t main()
{
	IOS
	ll T = 1;
	// cin >> T;
	for (ll i = 1; i <= T; ++i)
	{
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <stack>
#include <queue>
#include <list>
#include <stdio.h>
#include <algorithm>
#define MAX 100000
using namespace std;
typedef long long ll;
#define MAX 100000
vector<int> g[MAX];
int col[MAX];
void dfs(int s,int color)
{
	int v;
	col[s]=color;
	for(int i=0;i<g[s].size();i++)
	{
		v=g[s][i];
		if(col[v]==-1){
			dfs(v,color);
		}
	}
}
void init(int n)
{
	int id=0;
	for(int i=0;i<n;i++)
	{
		if(col[i]==-1){
			dfs(i,++id);
		}
	}
}
int main()
{	
	int n,m,num;
	int s,k;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		cin>>s>>k;
		g[s].push_back(k);
		g[k].push_back(s);
	}
	for(int i=0;i<n;i++)
	{
		col[i]=-1;
	}
	init(n);
	cin>>num;
	while(num--)
	{
		cin>>s>>k;
		if(col[s]==col[k]) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
	return 0;
}


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

int main() {

  string S;
  int N;

  cin >> N;
  cin >> S;
  vector<char> vec(N);
  int cur=0;
  vec.push_back(S.at(0));
  if (N!=1){
    for (int i=1;i<S.size();i++){
      if (S.at(i-1)!=S.at(i)){
          vec.push_back(S.at(i));
      }
    }
  }
  cout << vec.size()-N << endl; 
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int s, v[10005];
int main() {
	int i;
	cin>>s;
	for(i=1; ; i++) {
		if(!v[s]) v[s] = i;
		else break;
		s = s%2 ? 3*s+1 : s/2;
	}
	cout<<i;
	return 0;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define fil(x,t) memset(x,t,sizeof(x));
#define siz(x) ((int)x.size())
#define rep(i,a,n) for (int i=(a);i<(n);++i)
#define per(i,a,n) for (int i=(n)-1;i>=(a);--i)
#define foreach(e,x) for (__typeof(x.begin()) e=x.begin();e!=x.end();++e)
typedef long long ll;
typedef double db;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;

int read() {
  int f=1,x=0;char ch=getchar();
  while (ch<'0'||ch>'9') f=(ch=='-')?-1:1,ch=getchar();
  while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
  return f*x;
}

//head

const int N=1e5+5;
const int MAX=2e5+5;

int n;
int a[MAX],t[MAX];

int check(int v){
  int lim=(n<<1)-1;
  rep (i,0,lim) t[i]=(a[i]>=v)?1:0;
  int l=0,r=lim-1;
  rep (i,n-1,lim-1) if(t[i]==t[i+1]) {
    r=i;break;
  }
  per (i,1,n) if(t[i]==t[i-1]) {
    l=i;break;
  }
  if (r==lim-1&&l==0) return t[0];
  if (n-l-1<=r-n+1) return t[l];
  else return t[r];
}
int main(){
  scanf("%d",&n);
  int lim=(n<<1)-1;
  rep (i,0,lim) a[i]=read();

  int low=0,high=lim,ans=0;
  while (low<=high) {
    int mid=(low+high)>>1;
    if(check(mid)) ans=mid,low=mid+1;
    else high=mid-1;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr ll inf = 1ll<<62;

int main(){
    int n,q;
    cin>>n>>q;
    vector<tuple<int,int,int>> tar;
    set<pair<int,int>> d;
    for(int i=0;i<n;++i){
        int s,t,x;
        cin>>s>>t>>x;
        tar.emplace_back(x,s,t);
    }
    sort(tar.begin(),tar.end());
    for(int i=0;i<q;++i){
        int di;cin>>di;
        d.emplace(di,i);
    }
    vector<ll> result(q,-1);
    for(int i=0;i<n;++i){
        auto fir = d.lower_bound(make_pair(get<1>(tar[i]) - get<0>(tar[i]),0));
        auto las = d.lower_bound(make_pair(get<2>(tar[i]) - get<0>(tar[i])-1,q));
        for(auto it = fir;it!=las;++it){
                result[it->second] = get<0>(tar[i]);
        }
        d.erase(fir,las);
    }
    for(auto r : result)cout << r << endl;
    return 0;
}



Measured memory_bytes: 15216