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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    deque<int> d;
    for (int i = s.size() - 1; i >= 0; --i)
    {
        if (i == 0)
            break;
        bool flag = false;
        for (int j = min(i, m); j >= 1; --j)
        {
            if (s[i - j] == '0')
            {
                d.push_front(j);
                flag = true;
                i -= (j - 1);
                break;
            }
        }
        if (!flag)
        {
            M1;
            return;
        };
    }
    rep(i, d.size())
    {
        cout << d[i] << (i == (int)d.size() - 1 ? "\n" : " ");
    }
}

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


Measured memory_bytes: 976
#include <bits/stdc++.h>
#define N 510
using namespace std;
typedef pair<int,int> P;
int h,w;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};
bool mp[N][N][4],used[N][N],gxy[N][N];

bool onEdge(int x,int y){return (!x||!y||x==w+1||y==h+1);}
bool check(int x,int y){
  bool f[2]={};
  for(int i=0;i<4;i++){
    int nx=x+dx[i],ny=y+dy[i];
    f[mp[y][x][i]]|=(onEdge(nx,ny)||used[ny][nx]);
  }
  return f[0]&&f[1];
}


bool bfs(){
  memset(used,0,sizeof(used));
  queue<P>Q; 
  for(int i=1;i<=h;i++)
    for(int j=1;j<=w;j++) 
      if(check(j,i))Q.push(P(j,i)),used[i][j]=1;
  
  while(!Q.empty()){
    P t=Q.front();Q.pop();
    int x=t.first,y=t.second;
    if(gxy[y][x])return 1;
    for(int i=0;i<4;i++){
      int nx=x+dx[i],ny=y+dy[i];
      if(onEdge(nx,ny)||used[ny][nx]||!check(nx,ny))continue;
      Q.push(P(nx,ny));
      used[ny][nx]=1;
    }
  }
  return 0;
}

int main(){
  while(1){
    int sy,sx; 
    cin>>h>>w>>sy>>sx;
    if(!h&&!w&&!sy&&!sx)break;
    for(int i=1;i<=h+1;i++){
      for(int j=1,a;j<=w;j++)cin>>a,mp[i-1][j][2]=mp[i][j][0]=a;
      for(int j=1,a;j<=w+1&&i<h+1;j++)cin>>a,mp[i][j-1][1]=mp[i][j][3]=a;
    }
    
    memset(gxy,0,sizeof(gxy));
    bool ans=0;
    for(int i=0;i<4;i++){
      int nx=sx+dx[i],ny=sy+dy[i];
      if(!mp[sy][sx][i])gxy[ny][nx]=1,ans|=onEdge(nx,ny);
      }
    cout <<(ans||bfs()? "Yes":"No")<<endl;
  }
  return 0;

}

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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    int n; cin >> n;
    int a1 = 0, a2 = 0, a3 = 0, a4 = 0;
    REP(i, 0, n){
        string s; cin >> s;
        if(s == "AC"){
            a1++;
        }else if(s == "WA"){
            a2++;
        }else if(s == "TLE"){
            a3++;
        }else{
            a4++;
        }
    }
    cout << "AC x " << a1 << endl;
        cout << "WA x " << a2 << endl;
        cout << "TLE x " << a3 << endl;
        cout << "RE x " << a4 << endl;
}

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

namespace ABC042_A
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> numbers = Console.ReadLine()
                .Split(' ')
                .Select(str => int.Parse(str))
                .ToList<int>();

            numbers.Sort();

            int a = numbers[0];
            int b = numbers[1];
            int c = numbers[2];

            if (a == 5 && b == 5 && c == 7)
            {
                Console.WriteLine("YES");
            } else {
                Console.WriteLine("NO");
            }

        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
const long long MOD = 1000000007;

ll N, A[200010];
ll acc[200010];

signed main(){
    cin >> N;
    REP(i, N){
        cin >> A[i];
        acc[i + 1] = A[i] + acc[i];
    }
    ll ans = LONG_LONG_MAX;
    FOR(i, 2, N - 1){
        ll S1 = acc[i];
        ll j = lower_bound(acc, acc + i, S1 / 2) - acc;
        ll M1 = min(max(acc[j], S1 - acc[j]), max(acc[j - 1], S1 - acc[j - 1]));
        ll m1 = max(min(acc[j], S1 - acc[j]), min(acc[j - 1], S1 - acc[j - 1]));
        ll S2 = acc[N] - S1;
        j = lower_bound(acc + i, acc + N, S2 / 2 + S1) - acc;
        ll M2 = min(max(acc[j] - S1, S2 - (acc[j] - S1)), max(acc[j - 1] - S1, S2 - (acc[j - 1] - S1)));
        ll m2 = max(min(acc[j] - S1, S2 - (acc[j] - S1)), min(acc[j - 1] - S1, S2 - (acc[j - 1] - S1)));
        ans = min(ans, max(M1, M2) - min(m1, m2));
    }
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 6720
from typing import List


class UnionFind:
    """Union Find (Disjoint Set): O(α(N))
    References:
        https://github.com/atcoder/ac-library/blob/master/atcoder/dsu.hpp
        https://tumoiyorozu.github.io/single-file-ac-library/document_en/dsu.html
    """

    __slots__ = ["_data_size", "_roots"]

    def __init__(self, data_size: int) -> None:
        self._data_size = data_size
        self._roots = [-1] * data_size

    def __getitem__(self, x: int) -> int:
        """Find the group (root) of vertex x in O(α(n)) amortized."""
        while self._roots[x] >= 0:
            x = self._roots[x]
        return x

    def __len__(self) -> int:
        """Count the number of groups (roots)."""
        return len(self.groups)

    @property
    def groups(self) -> List[int]:
        """Return the set of groups (roots) in O(n)."""
        return [i for i, r in enumerate(self._roots) if r < 0]

    def is_connected(self, x: int, y: int) -> bool:
        """Return whether two vertices x and y are connected in O(α(n)) amortized."""
        return self[x] == self[y]

    def unite(self, x: int, y: int) -> None:
        """Unite two groups of vertices x and y in O(α(n)) amortized."""
        x, y = self[x], self[y]
        if x == y:
            return
        if self._roots[x] > self._roots[y]:
            x, y = y, x
        self._roots[x] += self._roots[y]
        self._roots[y] = x

    def get_size(self, x: int) -> int:
        """Return the size of the group where vertex x belongs in O(α(n)) amortized."""
        return -self._roots[self[x]]


import sys

readline = sys.stdin.buffer.readline

N, Q = map(int, readline().split())
tree = UnionFind(N)
res = []
for _ in range(Q):
    t, u, v = map(int, readline().split())
    if t:
        res.append(int(tree.is_connected(u, v)))
    else:
        tree.unite(u, v)
print("\n".join(map(str, res)))


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

# Cumulative sum
b = [0] * (n + 1)
for i in range(n):
    b[i+1] = b[i] + a[i]

# Count for each value
from collections import defaultdict
c = defaultdict(int)
for i in b:
    c[i] +=1

print(int(sum([v * (v - 1) / 2 for k, v in c.items()])))

Measured memory_bytes: 41400
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,v.size())
#define all(v)(v).begin(),(v).end()
#define bit(n)(1ll<<(n))
#define uniq(v)sort(all(v));v.erase(unique(all(v)),v.end())
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&s){}template<class T,class...U>void _print(ostream&s,T&&t,U&&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(T&&...t){_print(cout,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#else
template<class...T>void dprint(T&&...t){_print(cerr,t...);}
#endif
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>ostream&operator<<(ostream&o,const multiset<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}



int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int n;
    cin>>n;
    vi a(n);
    cin>>a;
    double ans=0;
    REP(i,n){
        ans+=1.0/a[i];
    }
    cout<<fixed<<setprecision(17)<<1.0/ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 998244353;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;
//typedef boost::multiprecision::cpp_int bigint;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL A, B, C;
	cin >> A >> B >> C;
	if (A == B && B != C)cout << "Yes\n";
	else if (B == C && C != A)cout << "Yes\n";
	else if (C == A && A != B)cout << "Yes\n";
	else cout << "No\n";
	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
c = []
for i in range(n):
	c.append(a[i]-(i+1))
c.sort()
#print (c)
b = c[int(n/2)]
xx = 0
for i in range(n):
	xx += abs(a[i]-(b + i +1))
print (xx)

Measured memory_bytes: 26836
#include <stdio.h>

int main(void){
    long long int i, k, a, b, ans = 1, hit = 0;
    scanf("%lld %lld %lld", &k, &a, &b);
    if(a+2<b){
        while(ans<a && k>0){
            ans++;
            k--;
        }
        if(k%2 == 1){
            ans++;
            k--;
        }
        ans += k/2*(b-a);
    }else{
        ans += k;
    }
    printf("%lld", ans);
}

Measured memory_bytes: 128
void main()
{
    long n, a, b;
    rdVals(n, a, b);
    long[] v = rdRow;

    long[][] comb = new long[][](n+1, n+1);
    comb[0][0] = 1;
    foreach (i; 1 .. n+1)
    {
        comb[i][0] = 1;
        foreach (j; 1 .. i+1)
        {
            comb[i][j] = comb[i-1][j-1] + comb[i-1][j];
        }
    }

    v.sort!"a > b";
    auto g = v.group.array;
    long num;
    long total;
    foreach (x; g)
    {
        if (num + x[1] < a)
        {
            num += x[1], total += x[0];
            continue;
        }

        double ave;
        long cnt;
        if (total)
        {
            long diff = a - num;
            total += x[0] * diff;
            ave = total.to!double / a;
            cnt = comb[x[1]][diff];
        }
        else
        {
            long m = min(x[1], b);
            ave = x[0].to!double;
            foreach (i; a .. m+1)
            {
                cnt += comb[x[1]][i];
            }
        }

        writefln("%.9f", ave);
        cnt.writeln;
        return;
    }
}

enum long mod = 10L^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;

int main(){
    int h, n;
    cin >> h >> n;
    int a, sum=0;
    REP(i, n){
        cin >> a;
        sum += a;
    }
    if(sum<h){
        cout << "No";
    } else {
        cout <<"Yes";
    }
    return 0;
}


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

int main(){
    long long k,a,b;
    cin>>k>>a>>b;
    ++k;
    long long ans=0;
    long long c=b-a;
    if(c<=0)ans=k;
    else{
        assert(b>a);
            if(k<a+2){
                ans=k;
            }
            else{
                int t=k-(a+2);
                ans+=b;
                if(t!=0)ans+=(b-a)*(t-t%2)/2;
                if(t%2==1)++ans;
            }
            ans=max(ans,k);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	private static final long x = (long) Math.pow(10, 18);

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();

		boolean can = true;
		if ((s.indexOf("N") == -1 && s.indexOf("S") != -1)) {
			can = false;
		} else if (s.indexOf("N") != -1 && s.indexOf("S") == -1) {
			can = false;
		} else if (s.indexOf("W") == -1 && s.indexOf("E") != -1) {
			can = false;
		} else if (s.indexOf("W") != -1 && s.indexOf("E") == -1) {
			can = false;
		}

		if (can) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();
	}

}


Measured memory_bytes: 35700
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f3f3f3f3f
#define PI acos(-1.0)
#define MOD 1000000007
#define R READ();
using namespace std;
typedef long long LL;
void READ()
{
    std::ios::sync_with_stdio(false);
//#ifdef ONLINE_JUDGE
//#else
//    freopen("555input.txt","r",stdin);
//    //freopen("555output.txt","w",stdout);
//#endif
}
#define N 1005
int ans,n,l,r;
int main()
{
    R
    cin>>n;
    while(n--)
    {
        cin>>l>>r;
        ans+=r-l+1;
    }
    cout<<ans;

    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<pll> vpll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  ll A, B;
  ll tmp = 1;
  IN(A,B);
  ll ans = 0;
  while(tmp<B){
    tmp += (A-1);
    ans++;
  }

  OUT(ans);

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

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

    multiset<int> st;

    rep(i, n) {
        if (st.empty()) {
            st.insert(a[i]);
        }
        else {
            auto it = st.lower_bound(a[i]);
            if (it == st.begin()) {
                st.insert(a[i]);
            }
            else {
                it--;
                st.erase(it);
                st.insert(a[i]);
            }
        }
    }

    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 8224
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//const int mod = 1e9+7;
const int N = 13;
int a[N][N];
int n, m, x;
int c[N];
bool res[(1 << N)];
int mon[(1 << N)];
int abi[(1 << N)][N];
inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int lowbit(int x) {
    return (x & (-x));
}

int main()
{
    quickread();
    cin >> n >> m >> x;
    for(int i = 0; i < n; i ++) {
        cin >> c[i];
        for(int j = 0; j < m; j ++) {
            cin >> a[i][j];
        }
    }
    int states = (1 << n);
    int ret = 0x3f3f3f3f;
    for(int st = 1; st < states; st ++) {
        int last = lowbit(st);
        int cnt = -1;
        mon[st] = mon[st - last];
        while(last) {
            cnt ++;
            last >>= 1;
        }
        mon[st] += c[cnt];
        bool flag = true;
        for(int i = 0; i < m; i ++) {
            abi[st][i] = abi[st-(1 << cnt)][i] + a[cnt][i];
            if(abi[st][i] < x) flag = false;
        }
        //cout << st << " " << mon[st] << endl;
        if(flag) ret = min(ret, mon[st]);
    }
    if(ret < 0x3f3f3f3f) cout << ret << endl;
    else cout << - 1<< endl;
    return 0;
}


Measured memory_bytes: 3848
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from fractions import Fraction

class UnionFind:

    def __init__(self, n):
        self.n = n
        self.par = [i for i in range(n)]
        self.height = [0 for i in range(n)]
        self.size = [1 for i in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        self.par[x] = self.find(self.par[x])
        return self.par[x]

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

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if self.height[x] < self.height[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = self.par[x]
            self.size[x] += self.size[y]
            if self.height[x] == self.height[x]:
                self.height[x] += 1

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

class BIT:
    def __init__(self, N):
        self.N = N
        self.bit = [0 for _ in range(N+1)]
    def add(self, x, a):
        while x <= self.N:
            self.bit[x] += a
            x += x & -x
    def sum(self, x):
        ret = 0
        while x > 0:
            ret += self.bit[x]
            x -= x & -x
        return ret

N, M = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]
ab.sort(key = lambda x: x[0])
ab.sort(key = lambda x: -x[1])
ans = 0
# print(ab)
uf = UnionFind(M+2)
bit = BIT(M)
ub = M+1
for a, b in ab:
    # print([bit.sum(i) for i in range(1, M+1)])
    i = M-a+1
    # print(bit.sum(i), i, ub)
    if 0 < i and bit.sum(i) < i:
        ans += b
        if bit.sum(i-1) == bit.sum(i):
            bit.add(i, 1)
            uf.unite(i, i+1)
        else:
            lb, ub = 0, i
            while lb+1 < ub:
                mid = (lb+ub)//2
                if uf.same(mid, ub):
                    ub = mid
                else:
                    lb = mid
            bit.add(lb, 1)
            uf.unite(lb, ub)
# print([bit.sum(i) for i in range(1, M+1)])
# print()
print(ans)


Measured memory_bytes: 126936
//============================================================================
// Name        : hoba.cpp :)
// Author      : (O_O Diab) (Why_not) (el 3AQ)
// Version     :
// Copyright   : please, Don't touch me :(
// Description : problem in C++
// MAIN IDEA   : combinatorics NCR
//============================================================================
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define rw freopen("graphs_as_a_service.txt","r",stdin),freopen("output.txt","w",stdout);
#define pb push_back
#define F first
#define S second
#define pf push_front
#define lp(i,a,b) for (int i=a;i<=(int)b;++i)
#define lp2(i,a,b) for (int i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define p(x) cout<<#x<<" = { "<<x<<" } \n"
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define rep(i,a) lp(i,0,a-1)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define EPS 1e-6
// to convert string to number use int a = stoi(string);
// to convert number to string use string s = to_string(int);
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define clr(c,x) memset(c,x,sizeof(c));
using namespace __gnu_pbds;
using namespace std;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
const int dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int N = 1e5 + 5, mod = (int) 1e9 + 7, INF = 0x3f3f3f3f;
vi pr, cnt;
vector<bool> vis;
int main() {
#ifdef ONLINE_JUDGE
	FAST
#endif
	vis.resize(N + 2, 1);
	cnt.resize(N + 2);
	vis[1] = 0;
	lp(i,2,N)
	{
		if (vis[i]) {
			pr.pb(i);
			for (int j = i + i; j <= N; j += i) {
				vis[j] = false;
			}
		}
	}
	for (auto u : pr) {
		int nxt = (u + 1) / 2;
		if (vis[nxt])
			cnt[u]++;
	}
	lp(i,1,N)
		cnt[i] += cnt[i - 1];
	int q;
	cin >> q;
	while (q--) {
		int l, r;
		cin >> l >> r;
		cout << cnt[r] - cnt[l - 1] << "\n";
	}
	return 0;
}


Measured memory_bytes: 1152
import java.util.*;
public class Main {


    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);

        int D = Integer .parseInt(scan.next());

        if(D == 25) System.out.println("Christmas");
        if(D == 24) System.out.println("Christmas Eve");
        if(D == 23) System.out.println("Christmas Eve Eve");
        if(D == 22) System.out.println("Christmas Eve Eve Eve");
    }
}

Measured memory_bytes: 21716
#include <stdio.h> 
int main(void)
{
	int H[500],W[500];
	int i=0,j=0,k=0,l=0;
	do{
		scanf("%d %d",&H[i],&W[i]);
		i++;
	}while(!(H[i-1]==0 && W[i-1]==0));
	
	for(j=0;j<=i-2;j++){
		/*?????¬???????¨???\*/
		for	(k=0;k<=W[j]-2;k++){printf("#");}
		printf("#\n");
		/*?????????????¨???\*/
		for(l=0;l<=H[j]-3;l++){
			printf("#");
			for(k=0;k<=W[j]-3;k++){
			printf(".");
			}
		printf("#\n");
		}
		/*??????????????¬????¨???\*/
		for	(k=0;k<=W[j]-1;k++){printf("#");}
		printf("\n\n");
		
	}
	
	return 0;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


li a[200200] = {0};
li dp[200200];

int main() {
    li n;
    cin >> n;
    rin{cin >> a[i];}
    rin{
        dp[a[i]] = dp[a[i] - 1] + 1;
    }
    li ma = 0;
    rep(i, n + 1) {
        ma = max(ma, dp[i]);
    }
    cout << n - ma << endl;

    return 0;
}

Measured memory_bytes: 3328
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		long N = long.Parse(Console.ReadLine());
		long ans = 0;
		for(long i=1;i<=10000001;i++){
			long a = (N-i)/i;
			if(a>i){
				if((N-i)%i==0){
					ans += a;
				}
			} else {
				break;
			}
		}
		Console.WriteLine(ans);
	}
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vect(N);
  for (int i = 0; i < N; i++) {
    cin >> vect.at(i);
  }
  sort(vect.begin(), vect.end());
  reverse(vect.begin(), vect.end());
  int diff = 0;
  for (int i = 0; i < N; i++) {
    diff += (1 - 2 * (i % 2)) * vect.at(i);
  }
  cout << diff << endl;
}

Measured memory_bytes: 256
def insertR(a, b):
  if a not in R: R[a] = {}
  if b not in R[a]: R[a][b] = 0

N = int(input())
A = list(map(int, input().split()))

if N == 1:
  print(1)
  exit()

DP = [[-1] * (N + 1) for _ in range(N + 1)]
D = [-1] * (N + 1)
R = {}
for i in range(5):
  a = A[i]
  if a in R:
    R[a] += 1
  else:
    R[a] = 1

Flag = 0
for i in R.keys():
  if R[i] >= 3:
    Flag = 1
    R[i] -= 3

L = []
for i in R.keys():
  if R[i] == 2:
    L.append(i)
    DP[i][i] = Flag
    D[i] = Flag
  elif R[i] == 1:
    L.append(i)
    D[i] = Flag

for i in range(len(L) - 1):
  for j in range(i + 1, len(L)):
    DP[L[i]][L[j]] = Flag

common = 0
for i in range(5, N * 3 - 3, 3):
  L = []
  for j in range(i, i + 3):
    for k in range(len(L)):
      if L[k][1] == A[j]:
        L[k][0] += 1
        break
    else :
      L.append([1, A[j]])
  L.sort()
  R = {}
  # 3
  if len(L) == 1:
    common += 1
  # 1:2
  elif len(L) == 2:
    a = L[0][1]
    b = L[1][1]
    # 1個のほうを揃える場合
    if DP[a][a] != -1:
      insertR(b, b)
      R[b][b] = max([R[b][b], DP[b][b], DP[a][a] + 1])
    # 2個のほうを揃える場合
    for j in range(N + 1):
      n = max(DP[b][j], DP[j][b])
      if n == -1: continue
      insertR(a, j)
      R[a][j] = max([R[a][j], DP[a][j], n + 1])
    # 揃えない場合
    for j in range(N + 1):
      n = D[j]
      if n == -1: continue
      insertR(a, j)
      R[a][j] = max(R[a][j], n)
      insertR(b, j)
      R[b][j] = max(R[b][j], n)
    n = max(D)
    insertR(a, b)
    R[a][b] = max(R[a][b], n)
    insertR(b, b)
    R[b][b] = max(R[b][b], n)
  # 1:1:1
  elif len(L) == 3:
    a = L[0][1]
    b = L[1][1]
    c = L[2][1]
    insertR(b, c)
    insertR(a, c)
    insertR(a, b)
    #揃える場合
    if DP[a][a] != -1:  
      R[b][c] = max(R[b][c], DP[a][a] + 1)
    if DP[b][b] != -1:      
      R[a][c] = max(R[a][c], DP[b][b] + 1)
    if DP[c][c] != -1:
      R[a][b] = max(R[a][b], DP[c][c] + 1)
    #揃えない場合
    for j in range(N + 1):
      n = D[j]
      if n == -1: continue
      insertR(a, j)
      R[a][j] = max(R[a][j], n)
      insertR(b, j)
      R[b][j] = max(R[b][j], n)
      insertR(c, j)
      R[c][j] = max(R[c][j], n)
    n = max(D)
    R[a][b] = max(R[a][b], n)
    R[b][c] = max(R[b][c], n)
    R[a][c] = max(R[a][c], n)

  for k in R.keys():
    for kk in R[k].keys():
      n = R[k][kk]
      DP[k][kk] = max(DP[k][kk], n)
      DP[kk][k] = max(DP[kk][k], n)
      D[k] = max(D[k], n)
      D[kk] = max(D[kk], n)

a = A[-1]
if DP[a][a] != -1:
  DP[a][a] += 1

ans = 0
for i in DP:
  for j in i:
    ans = max(ans, j)

ans += common

print(ans)

Measured memory_bytes: 128420
package main

import (
	"fmt"
	"math"
	"sort"
)

func abs(a int) int {
	if a < 0 {
		return -a
	} else {
		return a
	}
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}



func main() {
	var n int
	fmt.Scan(&n)
	a:=make([]int,n)
	for i:=0;i<n;i++{
		fmt.Scan(&a[i])
	}
	sort.IntSlice(a).Sort()
	maxA:=a[len(a)-1]
	dp:=make([]bool,maxA+1)

	count:=0
	for i:=0;i<n-1;i++{
		if dp[a[i]]==true{
			continue
		}
		for j:=1;j<=maxA/a[i];j++{
			dp[j*a[i]]=true
		}
		if a[i]!=a[i+1]{
			count++
		}
	}
	if dp[maxA] == false {
		count++
	}
	fmt.Println(count)


}


Measured memory_bytes: 6452
/*
解法が分からなかった（アイデアが分からなかった）

*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


int main(){
    
    int n, m;
    cin >> n >> m;
    
    vector<int> p(m), y(m);
    
    for (int i = 0; i < m; i++) {
        cin >> p[i] >> y[i];
        p[i]--;
    }
    
    vector<vector<int>> vals(n);
    for (int i = 0; i < m; i++) vals[p[i]].push_back(y[i]);
    
    for (int i = 0; i < n; i++){
        sort(vals[i].begin(),vals[i].end());
    }
    
    for (int i = 0; i < m; i++){
        
        int v = p[i];
        printf("%06d",v+1);
        
        int id = lower_bound(vals[v].begin(),vals[v].end(), y[i]) - vals[v].begin();
        printf("%06d\n",id+1);
    }
}

Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define debug(x) cerr <<__LINE__<< ": " <<#x<< " = " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" = ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

template <unsigned int mod>
struct ModInt {
    ll x;
    ModInt() : x(0) {}
    ModInt(ll y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = (int) (1LL * x * p.x % mod); return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt pow(int64_t n) const {
        ModInt ret(1), mul(x);
        while(n > 0) {
            if(n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }
    ModInt inverse() const { return pow(mod - 2); }
    friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }
};

const int mod = 1000000007;
using mint = ModInt<mod>;

void solve() {
    int n;
    cin >> n;
    vector<ll> A(n);
    rep(i, n) cin >> A[i];
    vector<mint> X(60, 0);
    rep(i, n) {
        rep(j, 60) {
            if (A[i] >> j & 1) X[j] += 1;
        }
    }
    mint ans = 0;
    rep(i, 60) {
        ans += X[i] * (-X[i] + n) * mint(2).pow(i);
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 5576
using System;

class Program
{
    static void Main(string[] args)
    {
        long N = long.Parse(Console.ReadLine());
        long ans = 100;

        for(long i = 1; i * i <= N; i++)
        {
            if (N % i == 0)
            {
                long Q = N / i;
                long temp = 1;
                while (true)
                {
                    if (Q / 10 >= 1)
                    {
                        Q /= 10;
                        temp++;
                    }
                    else break;
                }
                ans = Math.Min(ans, temp);
            }
        }
        Console.WriteLine(ans);
    }
}

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

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


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

int main() {
  int N;
  string S;
  cin >> N >> S;
  
  if (N % 2 != 0) {
    cout << "No" << endl;
    return 0;
  }
  
  for (int i = 0; i < N / 2; i++) {
    if (S[i] != S[N / 2 + i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

const int N = 1e5 + 10;
int c[N];
vector<int> a[N];

bool DFS(int u, int k) {
  c[u] = k;
  for (auto& v : a[u]) {
    if (c[v] >= 0) {
      if (c[v] != 1 - k) return true;
    } else {
      if (DFS(v, 1 - k)) return true;
    }
  }
  return false;
}

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int k = 0; k < m; ++k) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x; --y;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  fill(c, c + n, -1);
  bool conflict = DFS(0, 0);
  if (conflict) {
    printf("%lld\n", (int64)n * (n - 1) / 2 - m);
  } else {
    int sum = 0;
    for (int i = 0; i < n; ++i) {
      sum += (c[i] == 0);
    }
    printf("%lld\n", (int64)sum * (n - sum) - m);
  }
  return 0;
}


Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,m;
  cin>>n>>m;
  vector<vector<ll>> mat(n,vector<ll>(m));
  for(ll i=0;i<n;i++)
    for(ll j=0;j<m;j++){
      char ch;
      cin>>ch;
      if(ch =='.')
        mat[i][j] = 1;
      else 
        mat[i][j]=0;
    }
    
  vector<vector<ll>> r(n,vector<ll>(m));
  vector<vector<ll>> l(n,vector<ll>(m));
  vector<vector<ll>> u(n,vector<ll>(m));
  vector<vector<ll>> d(n,vector<ll>(m));
  for(ll i=0;i<n;i++)
    for(ll j=0;j<m;j++){
      if(j==0)
        l[i][j] = mat[i][j];
      else if(mat[i][j])
        l[i][j] = l[i][j-1] +1;
    }
  
  for(ll i=0;i<n;i++)
    for(ll j=m-1;j>=0;j--){
      if(j==m-1)
        r[i][j] = mat[i][j];
      else if(mat[i][j])
        r[i][j] = r[i][j+1] +1;
    }
  
  for(ll i=0;i<n;i++)
    for(ll j=0;j<m;j++){
      if(i==0)
        u[i][j] = mat[i][j];
      else if(mat[i][j])
        u[i][j] = u[i-1][j] +1;
    }
  
  for(ll i=n-1;i>=0;i--)
    for(ll j=0;j<m;j++){
      if(i==n-1)
        d[i][j] = mat[i][j];
      else if(mat[i][j])
        d[i][j] = d[i+1][j] +1;
    }
  ll ans=0;
  
  for(ll i=0;i<n;i++)
    for(ll j=0;j<m;j++)
      ans = max(ans,l[i][j] + d[i][j] +u[i][j] + r[i][j] - 3);
    cout<<ans<<endl;
}

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

int descending_compare(const void *a, const void *b){
    if (*(long long*)a > *(long long*)b){
        return -1;
    }else if (*(long long*)a == *(long long*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

//greatest common divisor
unsigned long gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}

unsigned long lcm(unsigned long x, unsigned long y){
    unsigned long g = gcd(x, y);
    return x*y/g;

}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}

/*
int struct_ascending_compare(const void *p, const void *q) {
return ((struct_name*)p)->member_name - ((struct_name*)q)->member_name;
}*/

/*unsigned long long pascal[100][100] = {0};
void make_pascal(void){
    for (int i = 0; i < 100; i++){
        pascal[i][0] = 1;
    }
    pascal[1][1] = 1;
    for (int i = 2; i < 100; i++){
        for (int j = 1; j < 100; j++){
           pascal[i][j] = (pascal[i-1][j-1]+pascal[i-1][j]);
        }
    }
}*/
long long mod = 1000000007;

long long mod_pow(long long x, long long n){
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % mod;
        x = x * x % mod;
    }
    return res;
}


int main(void){
    long long n;
    long long cpy;
    long long ans = 0;
    scanf("%lld", &n);
    cpy = n;
    while (cpy > 0){
        if (cpy % 10 != 9 && cpy/10 > 0){
            ans += 9;
            cpy -= 10;
        }else{
            ans += cpy%10;
        }
        cpy /= 10;
    }

    printf("%lld\n", ans);

    return 0;
}

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

int main(){
    int a,b;
    string s;
    cin >> a >> b >> s;
    for(int i = 0; i < a+b+1; i++){
        if(i == a && s[i] != '-'){
            cout << "No" << endl;
            return 0;
        }else if(i != a && s[i] == '-'){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
typedef struct
{
  double x;
  double y;
} XY;
int koch (XY ,XY ,int );
int main()
{
  int n;
  XY a1,a2;
  scanf("%d",&n);
  a1.x=0;
  a1.y=0;
  a2.x=100;
  a2.y=0;
  printf("%f %f\n",a1.x,a1.y);
  koch(a1,a2,n);
  return 0;
}

int koch(XY a1,XY a2,int n)
{
  XY b,c,d,leng;
  if (n==0){
    printf("%f %f\n",a2.x,a2.y);
    return 0;
  }

  leng.x = (a2.x - a1.x)/3;
  leng.y = (a2.y - a1.y)/3;
  b.x = leng.x + a1.x;
  b.y = leng.y + a1.y;
  c.x = leng.x * cos(M_PI/3.0) - leng.y * sin(M_PI/3.0)+b.x;
  c.y = leng.x * sin(M_PI/3.0) + leng.y * cos(M_PI/3.0)+b.y;
  d.x = a2.x - leng.x;
  d.y = a2.y - leng.y;

  koch(a1,b,n-1);
  koch(b,c,n-1);
  koch(c,d,n-1);
  koch(d,a2,n-1);
}

Measured memory_bytes: 636
def solve(n,left,right):
    if n==0:
        return 1
    if a[n-1]>left:
        return solve(n-1,a[n-1],right)
    if a[n-1]>right:
        return solve(n-1,left,a[n-1])
    return 0

n=int(input())
for _ in range(n):
    a=[int(i) for i in input().split()][::-1]
    print("YES" if solve(10,0,0) else "NO")

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

#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	int N,A;
	cin >> N >> A;
	if (N % 500 <= A)
		cout << "Yes";
	else
		cout << "No";
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <cstdio>

static const int MAX=100;
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;
static const int NIL=-1;

using namespace std;

int adj[MAX+1][MAX+1];
int color[MAX+1],d[MAX+1],f[MAX+1];
stack<int> S;
int n;
int t=0;

int next(int u){
  for(int i=1;i<=n;i++){
    if(adj[u][i]==1&&color[i]==WHITE) return i;
  }
  return NIL;
}

void dfs(int u){
  S.push(u);
  color[u]=GRAY;
  d[u]=++t;
  while(S.empty()==false){
    u=S.top();
    int v=next(u);
    if(v!=NIL){
      color[v]=GRAY;
      d[v]=++t;
      S.push(v);
    }else{
      S.pop();
      color[u]=BLACK;
      f[u]=++t;
    }
  }
}

void dfs_init(){
  for(int i=1;i<=n;i++) color[i]=WHITE;
  for(int i=1;i<=n;i++){
    if(color[i]==WHITE) dfs(i);
  }
}

int main(){
  cin >> n;
  for(int i=1;i<=n;i++){
    int u,k; cin >> u >> k;
    for(int i=1;i<=n;i++) adj[u][i]=0;
    for(int i=0;i<k;i++){
      int v; cin >> v;
      adj[u][v]=1;
    }
  }
  dfs_init();
  for(int id=1;id<=n;id++){
    printf("%d %d %d\n",id,d[id],f[id]);
  }
}

Measured memory_bytes: 3180
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

const int MX = 1000005;
const int MM = 1000000007;

int N, T;
int D[MX];

int main()
{
	scanf("%d%d", &N, &T);
	for(int i = 1; i <= N; i++) scanf("%d", D+i);
	int tot = 0, lst = D[1];
	for(int i = 2; i <= N; i++){
		if( D[i] >= D[i-1] + T ) tot += T;
		else tot += D[i] - D[i-1];
		lst = D[i];
	}
	printf("%d\n", tot+T);
}


Measured memory_bytes: 896
n = int(input())
a = list(map(int, input().split()))
cnt4 = 0
cnt2 = 0
for i in a:
    if i % 4 == 0:
        cnt4 += 1
    elif i % 2 == 0:
        cnt2 += 1
if cnt2 == 0:
    cnt2 = 1
print("Yes" if cnt4 >= (n - (cnt2 - 1)) // 2 else 'No')


Measured memory_bytes: 14252
numbers=[]
for i in range(1000000):
	numbers.append(True)
numbers[0]=False
numbers[1]=False

idx=1
multiple=1

while True:
	idx+=1
	multiple=idx
	if idx>1000000**(1/2):
		break
	while True:
		if 999999<idx*multiple:
			break
		numbers[idx*multiple]=False
		multiple+=1
#print(numbers)


def count(n):#関数「count」を定義
	cnt=0
	for i in range(n+1):
		if numbers[i]==True:
			cnt+=1
	print(cnt)


while True:
	try:
		n=int(input())
		count(n)
	except EOFError:
		break


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

#define rep(i, a, b) for(int i = (a); i < int(b); ++i)
#define rrep(i, a, b) for(int i = (a) - 1; i >= int(b); --i)
#define trav(it, v) for(auto &it : (v))
#define all(v) (v).begin(), (v).end()
#define what_is(x) cerr << #x << " is " << x << endl;
#define sz(x) (int)(x).size()

typedef double fl;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;

int main(){
	ios::sync_with_stdio(0);
    ll K, A, B;
    cin >> K >> A >> B;
    if (A >= B-2 || K <= A) {
        cout << K+1 << endl;
        return 0;
    }
    ll has = A;
    K -= A-1;
    if (K%2) {
        has++;
        K--;
    }
    has += (B-A)*(K/2);
    cout << has << endl;
}

Measured memory_bytes: 256