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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define sz(c) (static_cast<int>(c.size()))
#define endl "\n"

using ld = long double;
using ll = long long;

inline ll addm(ll __a, ll __b, ll __m);
inline ll subm(ll __a, ll __b, ll __m);
inline ll mulm(ll __a, ll __b, ll __m);
ll powm(ll __a, ll __b, ll __m);
ll inv(ll __x, ll __m);
// }}}

const ll INFL = numeric_limits<ll>::max() / 2;
const ll INF = numeric_limits<int>::max() / 2;
const ll MOD = 1e9+7;

const int N = 10500;
const int D = 105;

ll mem[D][N];
int d;

ll dp(int s, int l)
{
    if (l == 0) return (s == 0);
    ll &ret = mem[s][l];
    if (ret != -1) return ret;
    ret = 0;
    for (int i = 0; i <= 9; i++) {
        ret = (ret + dp((s + i) % d, l-1)) % MOD;
    }
    return ret;
}

void solve()
{
    memset(mem, -1, sizeof(mem));
    string k;
    cin >> k >> d;
    int n = sz(k);
    ll ans = 0;
    int cur = 0;
    for (int l = 0; l < n; l++) {
        for (int g = 0; g < k[l]-'0'; g++) {
            int sum = cur + g;
            ans = (ans + dp(sum % d, n-l-1)) % MOD;
        }
        cur += k[l]-'0';
    }
    if (cur % d != 0) ans = (ans+MOD-1)%MOD;
    cout << ans << endl;
}

// main {{{
int main()
{
    cin.sync_with_stdio(0); cin.tie(NULL);
    solve();
    return 0;
}

inline ll addm(ll __a, ll __b, ll __m = MOD) {
    return ((__a+__b)%__m);
}
inline ll subm(ll __a, ll __b, ll __m = MOD) {
    return (((__a-__b)%__m+__m)%__m);
}
inline ll mulm(ll __a, ll __b, ll __m = MOD) {
    return ((__a*__b)%__m);
}
ll powm(ll __a, ll __b, ll __m = MOD) {
    ll ret = (!__b) ? 1 : powm(__a, __b/2, __m);
    return (!__b) ? 1 : mulm(mulm(ret, ret, __m), (__b%2) ? __a : 1, __m);
}
ll inv(ll __x, ll __m = MOD) {
    return powm(__x, __m-2, __m);
}
// }}}


Measured memory_bytes: 9472
#include<stdio.h>
int n;
int A[101][101];
typedef struct{
  int d;
  int f;
}node;
node P[101];
int c=0;
void dfs(int s){
  int i;
  for(i=0;i<n;i++){
    if(A[s][i+1]==1){
      //printf("a%d %d\n",s,i+1);
      if(P[i+1].d == 0){
	//printf("b%d %d\n",i+1,c);
	P[i+1].d = ++c;
	dfs(i+1);
      }
      else continue;
    }
  }
  if(P[s].f==0) P[s].f = ++c;
  return ;
}
int main(){
  int i,j;
  int u,k,v;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      A[u][v]=1;
    }
  }
  for(i=0;i<n;i++){
    if(P[i+1].d == 0){
      P[i+1].d = ++c;
      dfs(i+1);
    }
  }
  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,P[i+1].d,P[i+1].f);
  }
  return 0;
}



Measured memory_bytes: 2052
def main():
    while True:
        H, W = tuple(map(int, input().split()))

        if (H, W) == (0, 0):
            break
        else:
            for i in range(H):
                if i == 0 or i == H - 1:
                    print("#"*W)
                else:
                    print("#"+"."*(W-2)+"#")
        print()

if __name__ == '__main__':
    main()



Measured memory_bytes: 5612
#C - Sum of gcd of Tuples (Easy)
# 1<=K<=200
# Kは整数
import math

K=int(input())

ans=0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            gcg=math.gcd(math.gcd(a,b),c)
            ans+=gcg
print(ans)

Measured memory_bytes: 68656
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    int N;
    string S,T;
    string ans="";
    cin >> N>>S>>T;
    REP(i,N){
        ans+=S[i];
        ans+=T[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
constexpr int M = 998244353;
long long modinv(int a, int m) {
    int x = m, y = a, p = 1, q = 0, r = 0, s = 1;
    while (y != 0) {
        int u = x / y;
        int x0 = y; y = x - y * u; x = x0;
        int r0 = p - r * u, s0 = q - s * u;
        p = r; r = r0; q = s; s = s0;
    }
    return q < 0 ? q + m : q;
}

int main() {
    int n; cin >> n;
    int cnt[int(1e6)+1] = {};
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        cnt[a]++;
    }
    long long g[int(1e6)+1] = {};
    for (int i = 1; i <= 1e6; i++) {
        long long sqs = 0, s = 0;
        for (long long j = i; j <= 1e6; j += i) {
            sqs += j * j % M * cnt[j] % M;
            s += j * cnt[j];
        }
        if (s >= M) s %= M;
        g[i] = (s * s - sqs) % M * ((M+1)/2) % M;
    }
    long long ans = 0;
    int mu[int(1e6)+1];
    fill(mu, mu+int(1e6)+1, 1);
    bool b[int(1e6)+1];
    fill(b, b+int(1e6), true);
    for (int p = 2; p*p <= 1e6; p++)
        if (b[p]) for (int q = p*p; q <= 1e6; q += p) b[q] = false;
    for (int p = 2; p <= 1e6; p++)
        if (b[p]) {
            for (int q = p; q <= 1e6; q += p) mu[q] *= -1;
            for (long long q = (long long)p*p; q <= 1e6; q += (long long)p*p) mu[q] = 0;
        }
    for (int i = 1; i <= 1e6; i++) {
        long long inv = modinv(i, M);
        long long s = 0;
        for (int j = 1; i*j <= 1e6; j++) s += mu[j] * g[i*j] % M;
        ans += s % M * inv % M;
    }
    cout << (ans % M + M) % M << endl;
}


Measured memory_bytes: 16896
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

struct hoge {
	double x;
	int a, n;
};
bool cmp(const hoge& l, const hoge& r) { return l.x < r.x; }

void foo(double x, int a, int n, int k, vector<hoge>& v) {
	hoge h = {x, a, n}; v.push_back(h);
	if (n <= 7)
		for (int i = k; a * i <= 12000; i++)
			foo(x + 1.0 / i, a * i, n + 1, i, v);
}

int main() {
	vector<hoge> v;
	foo(0, 1, 0, 1, v);
	sort(v.begin(), v.end(), cmp);
	vector<double> x;
	vector<int> a, n;
	for (int i = 0; i < v.size(); i++) {
		x.push_back(v[i].x);
		a.push_back(v[i].a);
		n.push_back(v[i].n);
	}
	for (;;) {
		int p, q, _a, _n;
		cin >> p >> q >> _a >> _n;
		if (p == 0) break;
		int l = lower_bound(x.begin(), x.end(), (double)p / q - EPS) - x.begin();
		int r = upper_bound(x.begin(), x.end(), (double)p / q + EPS) - x.begin();
		int cnt = 0;
		for (int i = l; i < r; i++)
			if (a[i] <= _a && n[i] <= _n)
				cnt++;
		cout << cnt << endl;
	}
}

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

int main() {
  string s;
  cin >> s;
  bool ans = true;
  if (s[2] != s[3]) ans = false;
  if (s[4] != s[5]) ans = false;
  cout << (ans ? "Yes" : "No") << endl;
  return 0;

  // if (s.at(2) == s.at(3) && s.at(4) == s.at(5)) {
  //   cout << "Yes" << endl;
  //   return 0;
  // } else {
  //   cout << "No" << endl;
  //   return 0;
  // }
};

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

bool solve(){
  int h,w;
  cin>>h>>w;
  vector<string> vec(h);
  rep(i,h) cin>>vec[i];

  vector<int> cnt(26,0);
  rep(i,h)rep(j,w) cnt[vec[i][j]-'a']++;

  int a=0,b=0,c=0;
  a = (h/2)*(w/2); //4
  b = (h%2)*(w/2) + (h/2)*(w%2); //2
  c = (h%2)*(w%2); //1

  // a
  rep(i,26) if(a>0 && cnt[i]>=4){
    int x = cnt[i]/4;
    cnt[i] %=4;
    a -= x;
    if(a<0){
      a=0;
      cnt[i] += -a*4;
    }
  }
  if(a>0) return false;

  // b
  rep(i,26) if(b>0 && cnt[i]>=2){
    int x = cnt[i]/2;
    cnt[i] %=2;
    b -= x;
    if(b<0){
      b=0;
      cnt[i] += -b*2;
    }
  }
  if(b>0) return false;

  // c
  rep(i,26) if(c>0 && cnt[i]){
    if(cnt[i]==1){
      c=0;
      cnt[i]=0;
    }
    else return false;
  }

  rep(i,26) if(cnt[i]>0) return false;

  return a==0 && b==0 && c==0;
}

int main(){
  if(solve()) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::collections::VecDeque;

fn main() {
    let n: usize = read();
    let mut a: Vec<i64> = vec![];
    let mut done: Vec<bool> = vec![false; n + 1];
    for _ in 0..n {
        let ai = read();
        a.push(ai);
    }
    let mut cb: usize = 1;
    let mut steps = 0;
    loop {
        done[cb] = true;
        steps += 1;
        let next_button = a[(cb - 1) as usize];
        cb = next_button as usize;
        if done[cb] {
            println!("-1");
            return;
        }
        if cb == 2 {
            break;
        }
    }
    println!("{}", steps)
}


Measured memory_bytes: 4352
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools


#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]


a = str(input())
if(a.isupper()):
  print("A")
else:
  print("a")



Measured memory_bytes: 68704
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<ctime>
#include<vector>
#include<map>
using namespace std;

int main(){
//srandom((unsigned long)time(NULL));

int n,k;
cin>>n>>k;
string s;
cin>>s;

char x[]={'A','B','C'};
char y[]={'a','b','c'};

for(int i=0;i<3;i++){
    if(s[k-1]==x[i]){
        s[k-1]=y[i];
    }
}

cout<<s<<endl;

return 0;
}

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

int max(int a, int b ){
    if(a>=b) return a;
     return b ;
}


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

    int ans = 0;
    for(int i=1;i<1001;i++){
        for(int j=2;j<1001;j++){
          if(pow(i,j)>x) break ; 
          ans = max(ans,pow(i,j)) ;
        }
    }
    
    cout << ans << endl ;  
	return 0;
}



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

int main(){
  int N;
  cin >> N;
  set<string> used;
  char c;
  for(int i = 0; i < N; ++i){
    string s;
    cin >> s;
    if(used.count(s) > 0){
      cout << "No" << endl;
      return 0;
    }
    used.insert(s);
    if(i > 0 && s[0] != c){
      cout << "No" << endl;
      return 0;
    }
    c = s.back();
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
c=[[False for i in range(13)]for j in range(4)]
n=int(input())
for i in range(n):
    s=input()
    mark=s.split(' ')[0]
    rank=int(s.split(' ')[1])
    if mark=='S':
        c[0][rank-1]=True
    elif mark=='H':
        c[1][rank-1]=True
    elif mark=='C':
        c[2][rank-1]=True
    else:
        c[3][rank-1]=True
for i in range(4):
    for j in range(13):
        if c[i][j]==False:
            mark=''
            if i==0:mark='S'
            elif i==1:mark='H'
            elif i==2:mark='C'
            else:mark='D'
            print(mark+' '+str(j+1))

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

using namespace std;

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

  string s; cin >> s;
  int k = 15 - s.size();

  for(auto &c : s) {
    if(c == 'o') ++k;
  }

  if(k >= 8) {
    cout << "YES";
  } 
  else cout << "NO";



  return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itn int

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


int main()
{
  long double h, w;
  cin >> h >> w;
  if(int(h) % 3 == 0 || int(w) % 3 == 0){
    cout << 0 << endl;
  }else{
    ll res1 = LLONG_MAX;
    ll res3 = LLONG_MAX;
    for (int i = 1; i < h; i++) {
      ll s1 = ll(w / 2) * i;
      ll s2 = ceil(w / 2) * i;
      ll s3 = w * (h-i);
      res1 = min(res1, max({s1, s2, s3}) - min({s1, s2, s3}));
      ll s4 = w * int((h - i) / 2);
      ll s5 = w * ceil((h - i) / 2);
      res3 = min(res3, max({s3, s4, s5}) - min({s3, s4, s5}));

    }

    ll res2 = LLONG_MAX;
    ll res4 = LLONG_MAX;
    for (int i = 1; i < w; i++) {
      ll s1 = ll(h / 2) * i;
      ll s2 = ceil(h / 2) * i;
      ll s3 = h * (w-i);
      res2 = min(res2, max({s1, s2, s3}) - min({s1, s2, s3}));
      ll s4 = h * int((w - i) / 2);
      ll s5 = h * ceil((w - i) / 2);
      res4 = min(res4, max({s3, s4, s5}) - min({s3, s4, s5}));
    }


    cout << min({res1, res2, res3, res4}) << endl;
  }

}


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

namespace ConsoleAppTest
{
    class Multiplication3
    {
        static void Main(string[] args)
        {
            long A;
            decimal B;

            //2つ以上のスペース区切り入力の取得
            string[] str = Console.ReadLine().Split(' ');
            A = long.Parse(str[0]);
            B = decimal.Parse(str[1]);

            Console.WriteLine((long)(A*B));
        }
    }
}


Measured memory_bytes: 27544
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

string s, t;
int p[30];

signed main() {
	cin >> s >> t;
	fill(p, p + 30, 30);
	for (int i = 0; i < (int)s.size(); i++) {
		int x = s[i] - 'a';
		int y = t[i] - 'a';
		if (p[x] < 26) {
			if (p[x] != y) {
				cout << "No" << endl;
				return 0;
			}
		}
		else p[x] = y;
	}
	for (int i = 0; i < 26; i++)for (int j = i + 1; j < 26; j++)if (p[i] == p[j] && p[i] != 30) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 776
R,G,B,N=list(map(int, input().split()))
arr = [R,G,B]
arr = sorted(arr, reverse=True)
R,G,B = arr

cnt = 0
for r in range(N//R+1):
    for g in range((N-r*R)//G+1):
        tmp = (N-(r*R+g*G))
        if tmp>=0:
            if tmp%B==0:
                cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  map<ll, ll> cnt;
  rep(i, n) {
    cnt[a[i]]++;
  }
  ll ans = 0;
  for (auto it = cnt.begin(); it != cnt.end(); ++it) {
    ll key = it->first;
    ll value = it->second;
    if(value >= key) ans += value - key;
    else ans += value;
  }
  cout << ans << endl;
}

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

int main() {
	long long N, A, B;
	cin >> N >> A >> B;
	long long a = N / (A + B);
	long long b = N % (A + B);
	long long total = 0;
	total += a * A;
	if (b <= A) {
		total += b;
	}
	else {
		total += A;
	}
	cout << total << endl;
}

Measured memory_bytes: 3624
while ary  =  gets
  ary.chomp
  stack = []
  ary = ary.split(" ")
  while ary.size>0
    a = ary.shift
    if  a == "+"
      x = stack.shift.to_i + stack.shift.to_i
    elsif a == "-"
      x = -stack.shift.to_i + stack.shift.to_i
    elsif a == "*"
      x = stack.shift.to_i * stack.shift.to_i 
    else
      x = a
    end
    stack.unshift(x)
    
    end
    puts stack[0]
end

Measured memory_bytes: 8640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int min, max;
  cin >> min >> max;
 
  // ここにプログラムを追記
  int s1, s2, s3, s4, s5;
  int ans;
  int count = 0;
  for (int i=min; i<=max; i++) {
    s1 = i/10000;
    s2 = i/1000 - s1*10;
    s3 = i/100 - s2*10 - s1*100;
    s4 = i/10 - s3*10 - s2*100 - s1*1000;
    s5 = i - s4*10 - s3*100 - s2*1000 - s1*10000;
    ans = s5*10000 + s4*1000 + s3*100 + s2*10 + s1;
    if (ans - i == 0) {
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)

int main(){
	int d;
	cin >>d;
	cout <<"Christmas";
	rep(i,abs(d-25)){
		cout << " Eve";
	}
}

Measured memory_bytes: 256
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    s = str(readline().rstrip().decode('utf-8'))
    c = collections.Counter(list(s))
    left = collections.defaultdict(int)
    cnt = 0
    for i in range(n - 2):
        left[s[i]] += 1
        mid = collections.defaultdict(int)
        for k, v in left.items():
            mid[k] += v
        for j in range(i + 1, n - 1):
            mid[s[j]] += 1
            if s[i] != s[j]:
                if [s[i], s[j]].count("R") == 0:
                    cnt += c["R"] - mid["R"]
                    if j + j - i < n:
                        if s[j+j-i] == "R":
                            cnt -= 1
                elif [s[i], s[j]].count("G") == 0:
                    cnt += c["G"] - mid["G"]
                    if j + j - i < n:
                        if s[j+j-i] == "G":
                            cnt -= 1
                elif [s[i], s[j]].count("B") == 0:
                    cnt += c["B"] - mid["B"]
                    if j + j - i < n:
                        if s[j+j-i] == "B":
                            cnt -= 1
    print(cnt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 69636
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    ll ans=0;
    if(a+b+1>=c)ans=b+c;
    else ans=1+b*2+a;
    cout<<ans<<endl;
    return 0;
}

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

#define eb emplace_back
#define sz(s) (int)(s.size())
#define all(s) s.begin(), s.end()
#define ll long long

const int N = 2e6;
const int INF = 1e9;

void solve() {
	int h, n;
	cin >> h >> n;
	int sum = 0;
	for (int i = 1; i <= n; ++ i) {
		int x;
		cin >> x;
		sum += x;
	}
	cout << (sum >= h ? "Yes" : "No");
}

int main () {
	cerr << "Ready\n";
	solve();
	return 0;
}

Measured memory_bytes: 256
def getval():
    n = int(input())
    p = list(map(float,input().split()))
    return n,p

def main(n,p):
    dp = [[0 for i in range(n+1)] for i in range(n+1)]
    dp[1][1] = p[0]
    dp[1][0] = 1 - p[0]
    for i in range(2,n+1):
        locp = p[i-1]
        for j in range(n+1):
            dp[i][j] = dp[i-1][j] * (1 - locp)
            if j>0:
                dp[i][j] += dp[i-1][j-1] * locp
    print(sum(dp[n][(n+1)//2:]))
    #print(dp)

if __name__=="__main__":
    n,p= getval()
    main(n,p)  

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

int main(){
	int a,b,d,r;
	double f;
	cin >> a >> b;

	d = a/b;
	r = a%b;
	f = double(a)/double(b);

	printf("%d %d %.5f", d, r, f);

	return 0;
	
}

Measured memory_bytes: 1192
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define INF 9223372036854775807
#define MOD 1000000007
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0;
string s;
bool flag;
#pragma endregion



int main(void) {
  vll x, v, a1, a2, mx1, mx2;
  ll c, b1, b2;
  cin >> n >> c;

  x.pb(0);
  FOR(i, 0, n) {
	cin >> tmp;
	x.pb(tmp);
	cin >> tmp;
	v.pb(tmp);
  }
  x.pb(c);

  a1.pb(0);
  b1 = 0;
  mx1.pb(b1);
  FOR(i, 0, n) {
	m = a1[i] + v[i] - (x[i + 1] - x[i]);
	ans = max(ans, m);
	a1.pb(m);
	if (b1 < a1[i + 1]) {
	  mx1.pb(i + 1);
	}
	else {
	  mx1.pb(mx1.back());
	}
	b1 = max(b1, a1[i + 1]);
  }

  a2.pb(0);
  b2 = 0;
  mx2.pb(b2);
  FOR(i, 0, n) {
	m = a2[i] + v[n - i - 1] - (x[n - i + 1] - x[n - i]);
	ans = max(ans, m);
	a2.pb(m);
	if (b2 < a2[i + 1]) {
	  mx2.pb(i + 1);
	}
	else {
	  mx2.pb(mx2.back());
	}
	b2 = max(b2, a2[i + 1]);
  }

  FOR(i, 1, n + 1) {
	m = a1[i] + a2[mx2[n - i]] - x[i];
	ans = max(ans, m);
  }

  FOR(i, 1, n) {
	m = a1[mx1[n - i]] + a2[i] - (c - x[n - i + 1]);
	ans = max(ans, m);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 5780
from collections import deque

def bfs(graph, start, goal):
    s_stack = deque()
    g_stack = deque()
    visited = [0 for i in range(N+1)]
    s_stack.append([start,0])
    g_stack.append([goal, 0])
    visited[start] = 1 
    visited[goal] = 1 
    s_cnt = 1
    g_cnt = 1
    round = 0
    while s_stack or g_stack:
        while s_stack:
            a,cost = s_stack.popleft()
            if cost > round:
                s_stack.appendleft([a,cost])
                break
            for b in graph[a].keys():
                if not visited[b]:
                    s_stack.append([b,cost+1])
                    visited[b] += 1 
                    s_cnt += 1
        while g_stack:
            a, cost = g_stack.popleft()
            if cost > round:
                g_stack.appendleft([a,cost])
                break
            for b in graph[a].keys():
                if not visited[b]:
                    g_stack.append([b,cost+1])
                    visited[b] += 1 
                    g_cnt += 1
        round += 1
    # print(s_cnt, g_cnt)
    # print(visited)
    return s_cnt > g_cnt

N = int(input())
graph = {i:{} for i in range(1,N+1)}
for i in range(N-1):
    a,b = map(int, input().split())
    graph[a][b] = graph[b][a] = 1
print('Fennec' if bfs(graph,1,N) else 'Snuke')


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

int main(){
    int n, m;
    cin >> n >> m;
    int s[10];
    char c[10];
    for(int i=0; i<m; i++){
        cin >> s[i] >> c[i];
    }

    bool isok = false;
    int start[3] = {0, 10, 100};
    int end[3] = {9, 99, 999};
    int ans = -1;
    for(int i=start[n-1]; i<=end[n-1]; i++){
        string str = to_string(i);
        bool isok = true;

        for(int j=0; j<m; j++){
            if(str[s[j]-1] != c[j]){
                isok = false;
                break;
            }
        }

        if(isok){
            ans = i;
            break;
        }
    }

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

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

namespace
{
	double func1(double x, double a, double b)
	{
		return 0.5 * (2.0*b - a * tan(x)) * a * a;
	}
	double func2(double x, double a, double b)
	{
		return 0.5 * b * b / tan(x) * a;
	}
}

void ABC144D()
{
	double PI = 3.1415926535897932384626433;
	double HALFPI = PI / 2.0;
	int a, b, x;
	cin >> a >> b >> x;
	double tan = (double)b / a;
	double y = 0.5 * b * b / tan * a;
	double cn = atan(tan);
	if (x > y)
	{
		double c1 = 0.0;
		double c2 = cn;
		while (true)
		{
			double cm = 0.5 * (c1 + c2);
			double r = func1(cm, a, b);
			if (abs(r - x) < 1.0e-10)
			{
				cout << std::fixed << std::setprecision(30) << cm * 180.0 / PI << endl;
				return;
			}
			if (r > x)
			{
				c1 = cm;
			}
			else
			{
				c2 = cm;
			}

		}
	}
	else
	{
		double c1 = cn;
		double c2 = HALFPI;
		while (true)
		{
			double cm = 0.5 * (c1 + c2);
			double r = func2(cm, a, b);
			if (abs(r - x) < 1.0e-10)
			{
				cout << std::fixed << std::setprecision(30) << cm * 180.0 / PI << endl;
				return;
			}
			if (r > x)
			{
				c1 = cm;
			}
			else
			{
				c2 = cm;
			}
		}
	}
}

int main()
{
	ABC144D();
	return 0;
}

Measured memory_bytes: 256
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

import scala.annotation.tailrec

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val s = in.readLine()

    val candidates = List("dream", "dreamer", "erase", "eraser")

    @tailrec
    def isMatch(ss: List[String]): Boolean = {
      ss match {
        case Nil => false
        case s :: rest =>
          if (s == "") {
            true
          } else {
            isMatch(
              rest ++ candidates.collect {
                case candidate: String if s.startsWith(candidate) =>
                  s.substring(candidate.length)
              }
            )
          }
      }
    }

    out.println(
      if (isMatch(List(s))) {
        "YES"
      } else {
        "NO"
      }
    )
    out.flush()
  }
}


Measured memory_bytes: 115592
#include <iostream>

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)

int main() {
	int N, M; cin >> N >> M;
	char A[50][50];
	char B[50][50];
	rep(i, 0, N) {
		rep(j, 0, N) {
			cin >> A[i][j];
		}
	}
	rep(i, 0, M) {
		rep(j, 0, M) {
			cin >> B[i][j];
		}
	}
	rep(i, 0, N) {
		rep(j, 0, N) {
			bool contains = true;
			rep(k, 0, M) {
				rep(l, 0, M) {
					if (i + k > N || j + l > N) {
						contains = false;
						break;
					}
					if (A[i + k][j + l] != B[k][l]) {
						contains = false;
						break;
					}
				}
				if (!contains) {
					break;
				}
			}
			if (contains) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn =2e5+10;
const int mod=1e9+7;


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
    ll a;
    double b;
    cin>>a>>b;
    b+=1e-6;
    ll d=b*100;
    ll ans=a*d/100;
    cout<<ans<<'\n';

}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
/**
********************************************************************
******************* Author:Bisnu sarkar ****************************
********************************************************************
**/
#define ull            unsigned long long
#define ll             long long
#define pii            pair<int,int>
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';

int set_1(int n,int pos){return n = (n | (1<<pos));}
int reset_0(int n,int pos){return n= n & ~(1<<pos);}
bool check_bit(int n,int pos){return n = n & (1<<pos);}

int dx[8]= {1,0,-1,0,-1,-1,1,1};
int dy[8]= {0,1,0,-1,-1,1,-1,1};
const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi=2* acos(0.0);
const double eps=1e-9;


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

    int t=1,te=0;
    // cin>>t;
    while(t--){
        ll n,m;
        cin>>n>>m;
        ll lcm,two=-1,xx;
        for(int i=1;i<=n;++i){
            ll x;
            cin>>x;

            if(i==1){
                int c=0; 
               
                while(x%2==0){
                    x/=2;
                    ++c;
                }
                lcm=x;
                two=c;
            }
            else{
                int c=0; 
                
                while(x%2==0){
                    x/=2;
                    ++c;
                }
                if(two != c){
                    printf("0\n");
                    return 0;
                }
                lcm=(x*lcm)/__gcd(x,lcm);
            }
        }
       // printf("%lld %lld\n", two,lcm);
        ll num= lcm*((ll)pow(2ll,(ll)two));

        ll ans=(2*m)/num;

        if(ans%2)ans=ans/2 + 1;
        else{
            ans/=2;
        }
        printf("%lld\n", ans);


        //printf("Case %d: ",++te);
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    int n;  cin>>n;
    vector<int>a(n);
    vector<int>b(n);
    rep(i, n){
        int x,y;    cin>>x>>y;
        a[i] = x+y;
        b[i] = x-y;
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    cout << max(a[n-1]-a[0], b[n-1]-b[0]) << endl;
}


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

int main() {
	int t;
	cin>>t;
	vector<string> v;
	while(t--){
	    string s;
	    cin>>s;
	    v.push_back(s);
	}
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	cout<<v.size();
	return 0;
}


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

int main(){
    int n;
    cin>>n;
    vector<string> s(n);
    for(int i=0; i<n; i++){
        string t;
        cin>>t;
        sort(t.begin(),t.end());
        s[i]=t;
    }
    sort(s.begin(),s.end());
    //s.erase(unique(s.begin(),s.end()),s.end());
    ll ans=0;
    ll same=1;
    for(int i=1; i<n; i++){
        if(s[i]==s[i-1])same++;
        else{
            ans+=(same*(same-1))/2;
            same=1;
        }
    }
    ans+=(same*(same-1))/2;
    cout<<ans;


    /*for(int i=0; i<n; i++){
        cout<<s[i]<<endl;
    }*/
    
    return 0;
}

Measured memory_bytes: 5760
// #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline")
// #pragma GCC option("arch=native", "tune=native", "no-zero-upper")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning")
// #pragma GCC option("D_GLIBCXX_PARALLEL","openmp")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

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

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

template <class T>
vector<T> divisor(T n) {
  vector<T> ret;
  for (T i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return ret;
}

void solve() {
  int N, M;
  cin >> N >> M;
  vector<ll> x(N), y(N), z(N);
  for (int i = 0; i < N; i++) cin >> x[i] >> y[i] >> z[i];
  ll ans = 0ll;
  for (int mask = 0; mask < 8; mask++) {
    vector<ll> vec;
    for (int i = 0; i < N; i++) {
      ll a = 0ll;
      a += ((mask & 1) ? 1 : -1) * x[i];
      a += ((mask & 2) ? 1 : -1) * y[i];
      a += ((mask & 4) ? 1 : -1) * z[i];
      vec.push_back(a);
    }
    sort(all(vec), greater<ll>());
    ll res = accumulate(vec.begin(), vec.begin() + M, 0ll);
    chmax(ans, res);
  }
  cout << ans << endl;
  return;
}

signed main() {
  fastio();
  solve();
  //   int t;
  //   cin >> t;
  //   while (t--) solve();

  // int t; cin >> t;
  // for(int i=1;i<=t;i++){
  //   cout << "Case #" << i << ": ";
  //   solve();
  // }
  return 0;
}


Measured memory_bytes: 256
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	K = int(input())
	A, B = getlist()
	for i in range(1001):
		if A <= K * i and K * i <= B:
			print("OK")
			return

	print("NG")
	


if __name__ == '__main__':
	main()

Measured memory_bytes: 64688
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int Maxn = 200005;

ll n, j, i;
ll a[Maxn];
ll sum, h;
int main() {
	cin >> n;
	for(i = 0; i < n; ++i) {
		cin >> a[i];
	}
	
	for(i = 0; i < n; ++i) {
		for(j; j < n; ++j) {
			if((h|a[j]) != h + a[j]) break;
			else h += a[j], sum += j - i + 1;
		}
		h -= a[i];
	}
	printf("%lld", sum);
	return 0;
}

Measured memory_bytes: 1792
import sys
input = sys.stdin.readline
from operator import itemgetter

def main():
	n, T = map(int, input().strip().split())
	s = [0] * n
	ans = 10**9
	for i in range(n):
		c, t = map(int, input().strip().split())
		if t <= T and c < ans:
			ans = c
	if ans == 10**9:
		print('TLE')
	else:
		print(ans)

if __name__ == '__main__':
	main()


Measured memory_bytes: 38256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
const int INF = 1 << 20;

int a, b, c;
int main()
{
	while(scanf("%d %d %d", &a, &b, &c) != EOF)
	{
		bool f = 0;
		for(int i = 1; b * i + c <= INF; i++)
		{
			if((b * i + c) % a == 0)
			{
				f = 1;
				break;
			}
		}
		if(f) printf("YES\n");
		else printf("NO\n");
	}
}

Measured memory_bytes: 128
n = input()
l = len(n)
ans = 0
stack = ["7", "3", "5"]

def check753(s):
  if "7" in s and "3" in s and "5" in s:
    return True
  else:
    return False


while stack:
  s = stack.pop()
  if int(n) >= int(s) and len(s) >= 3 and check753(s):
    ans+=1
  if len(s) < l:
    for i in ["7", "5", "3"]:
      stack.append(i+s)
      
print(ans)



Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    
    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());

        int K = Integer.parseInt(st.nextToken());

        int mod = 0;

        for (int i = 0; i < K; i++) {
            int target = mod * 10 + 7;

            if(target % K == 0) {
                pw.println(i + 1);
                br.close();
                pw.close();
                return;
            } else {
                mod = target % K;
            }
        }
        
        pw.println(-1);
        br.close();
        pw.close();
    }
}

Measured memory_bytes: 32888
#include <bits/stdc++.h>
using namespace std;
int n;
long long m;
long long ju(int x,vector<int>& a,vector<int>& cnt){
	long long sum=0;
	int t;
	for(int i=0;i<n;i++){
		t=max(0,x-a[i]);
		if(t<=a[0]) sum+=cnt[max(0,x-a[i])];
	}
	return sum;
}
int main(){
	cin>>n>>m;
	vector<int> a(n);
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a.begin(),a.end(),greater<int>());
	vector<int> cnt(a[0]+1);
	vector<long long> S(n);
	for(int i=0;i<n;i++){
		cnt[a[i]]++;
		S[i]=i>0?S[i-1]+a[i]:a[i];
	}
	for(int i=0;i<a[0];i++) cnt[a[0]-i-1]=cnt[a[0]-i]+cnt[a[0]-i-1];
	int le=0,ri=a[0]*2+1;
	long long j;
	while(le+1<ri){
		int mi=(le+ri)/2;
		j=ju(mi,a,cnt);
		if(j>=m) le=mi; else ri=mi;
	}
	int mn=le;
	long long ans=(m-ju(le,a,cnt))*mn;
	for(int i=0;i<n;i++){
		if(a[i]+a[0]<mn) break;
		le=0;ri=n;
		while(le+1<ri){
			int mi=(le+ri)/2;
			if(a[mi]<mn-a[i]) ri=mi; else le=mi;
		}
		ans+=1LL*(le+1)*a[i]+S[le];
	}
	cout<<ans<<endl;
}

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define FORr(i, j, k) for(int i = j; i >= k; --i)
#define repr(i, j) FOR(i, j, 0)
#define INF (1 << 30)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int main() {
	int a[3];
	scanf("%d %d %d", &a[0], &a[1], &a[2]);
	sort(a, a + 3);
	printf("%d\n", a[0] + a[1]);
	return 0;
}

Measured memory_bytes: 764
#include <stdio.h>
int main() {
    int N[2];
    for(int i=0;i<=1;i++){
    scanf("%d", &N[i]);
    }

    if(N[1]%N[0]==0){
        printf("%d",N[1]+N[0]);
    }else{
        printf("%d",N[1]-N[0]);

    }
   
 
    return 0;
}

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

int main(){
    int n,m;
    cin>>n>>m;
    int max_l=0,min_r=1e8;
    for(int i=0;i<m;++i){
        int l,r;
        cin>>l>>r;
        max_l=max(max_l,l);
        min_r=min(min_r,r);
    }
    cout<<max(0,min_r-max_l+1)<<endl;
}

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

int main(){
  int W,H,N;
  cin >>W>>H>>N;
  int data[N][3];
  for(int i=0;i<N;i++){
    cin>>data[i][0]>>data[i][1]>>data[i][2];
  }
  vector<int> x(W);
  vector<int> y(H);
  for(int i=0;i<N;i++){
    if(data[i][2]==1){
      for(int j=0;j<data[i][0];j++){
        x[j]=1;
      }
    }
    if(data[i][2]==2){
      for(int j=data[i][0];j<W;j++){
        x[j]=1;
      }
    }
    if(data[i][2]==3){
      for(int j=0;j<data[i][1];j++){
        y[j]=1;
      }
    }
    if(data[i][2]==4){
      for(int j=data[i][1];j<H;j++){
        y[j]=1;
      }
    }
  }
  int sum_x=0;
  int sum_y=0;
  for(int a:x){
    if(a==0)sum_x++;
  }
  for(int a:y){
    if(a==0)sum_y++;
  }
  cout << sum_x*sum_y<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
 
using namespace std;
 
 int dp[4002][4002] = {0};
 
 
int main(){
 
char a[4003];
 
char b[4003];
 
 while (scanf("%s%s",a,b)!=EOF) {
 
 
   memset(dp,0,sizeof(dp));
   // int dp[4002][4002] = {0};
 
   /*
    for(int i = 0;i < 10;i++){
      for(int j = 0;j < 10;j++){
        cout << dp[i][j];
      }
    }
   */
 
    int ans = 0;
    //  scanf("%s",a);
 
  int alen = strlen(a);
 
  //  if(alen == 0) break;
 
  //  scanf("%s",b);
 
 
 
  int blen = strlen(b);
 
  //  cout << "ans:" << ans << endl;
 
 
 
  for(int i = 1;i <= alen;i++){
    for(int j = 1;j <= blen;j++){
      if(a[i-1] == b[j-1]){
    dp[i][j] = dp[i-1][j-1]+1;
      }
      ans = max(ans,dp[i][j]);
    }
  }
 
  printf("%d\n",ans);
 
  }
 
  return 0;
 
}

Measured memory_bytes: 63716
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <bitset>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-8
# define MOD 1000000007
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
int Scan() {
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
const int N=2005;
//Code begin...

char s[N][N];
int P[N][N], E[N][N], U[N][N], L[N][N];

int main ()
{
    int n, m, Q, x1, x2, y1, y2;
    scanf("%d%d%d",&n,&m,&Q);
    FOR(i,1,n) scanf("%s",s[i]+1);
    FOR(i,1,n) FOR(j,1,m) {
        P[i][j]=P[i-1][j]+P[i][j-1]-P[i-1][j-1]+s[i][j]-'0';
        E[i][j]=E[i-1][j]+E[i][j-1]-E[i-1][j-1];
        if(s[i][j]=='1') {
            if (i>1&&s[i][j]==s[i-1][j]) ++E[i][j];
            if (j>1&&s[i][j]==s[i][j-1]) ++E[i][j];
        }
        U[i][j]=U[i][j-1]; L[i][j]=L[i-1][j];
        if (i>1&&s[i][j]=='1'&&s[i-1][j]=='1') ++U[i][j];
        if (j>1&&s[i][j]=='1'&&s[i][j-1]=='1') ++L[i][j];
    }
    while (Q--) {
        scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
        int p=P[x2][y2]-P[x1-1][y2]-P[x2][y1-1]+P[x1-1][y1-1];
        int e=E[x2][y2]-E[x1-1][y2]-E[x2][y1-1]+E[x1-1][y1-1]-(U[x1][y2]-U[x1][y1-1])-(L[x2][y1]-L[x1-1][y1]);
        printf("%d\n",p-e);
    }
    return 0;
}


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

    /*
    ||||||||||||||||||||||||||||||||||||||||||||||||
       |      |||         |      ||||    ||||  |   |
      | |     |   |      | |     |   |  |      |   |
     |   |    |    |    |   |    |   |  |      |   |
    |||||||   |    |   |||||||   |||     |||   |||||
    |     |   |   |    |     |   | |        |  |   |
    |     |   |||      |     |   |  ||  ||||   |   |
    ||||||||||||||||||||||||||||||||||||||||||||||||

    */
    using namespace std;
    #define ff first
    #define ss second
    #define mp make_pair
    #define all(v) v.begin(),v.end()
    #define int long long
    #define ll long long
    #define M 1000000007

    #define mii  map<ll ,ll >
    #define msi  map<string,ll >
    #define mis  map<ll int, string>
    #define rep(a,b)    for(ll i=a;i<b;i++)
    #define rep0(n)    for(ll i=0;i<n;i++)
    #define repi(i,a,b) for(ll i=a;i<b;i++)
    #define pb push_back
    #define vi vector<ll>
    #define mp make_pair
    #define vs vector<string>
    #define ppb pop_back
    #define endl '\n'
    #define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define r0 return 0;
    #define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
    #define FORE(it, c) for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
    #define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
    #define input freopen("input.txt", "r", stdin);
    #define Set(a, s) 4(a, s, sizeof (a))
    #define FOR repi
    //#define float long double
    ll max(ll a, ll b) { return (a > b)? a : b;}
    int min(int a, int b) { return (a < b)? a : b;}


     int solve()
     {
        int n;string s;
        cin>>n>>s;int a=0,b=0;
        rep0(n){if(s[i]=='R') a++;else b++;}
        if(a>b) {cout<<"Yes";}else cout<<"No";
     }
    signed main()
    {   
        
        int t=1;
        //cin>>t;
        while(t--)
        {
            solve();
        }     
        
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int n;
    cin >> n;
    vector<vector<ll>> cnt(10, vector<ll>(10));
    for ( int i = 1; i <= n; ++i ) {
        int w = i;
        while(1) {
            if ( w < 10 ) break;
            w /= 10;
        }
        ++cnt[w][i%10];
    }
    ll ans = 0;
    for ( int i = 1; i < 10; ++i ) {
        for ( int j = 1; j < 10; ++j ) {
            ans += cnt[i][j] * cnt[j][i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<queue>
#include<tuple>
#include<cmath>
using namespace std;

typedef tuple<int, int, int> T;

string c[1100000];
int H, W, K, X1, Y1, X2, Y2;

const long long INF = 1000000000000000;
bool exist = false;

int main(void){

    cin >> H >> W >> K; 
    cin >> X1 >> Y1 >> X2 >> Y2;
    for (int i = 1; i <= H; i++) cin >> c[i];

    char cyx[H+1][W+1];
    long long dis[H+1][W+1][4];

    for (int i = 1; i <= H; i++){
        string ch = c[i];
        for (int j = 0; j < W; j++){
            cyx[i][j + 1] = ch[j];
        }
    }

    queue<T> que;
    int dx[4] = {-1,0,1,0};
    int dy[4] = {0,-1,0,1};

    for (int i = 1; i <= H; i++){
        for (int j = 1; j <= W; j++){
            for (int k = 0;k < 4;k++) dis[i][j][k] = INF;
        }
    }

    for (int i = 0;i < 4;i++){
        que.push(T(X1,Y1,i));
        dis[X1][Y1][i] = 0;
    }

    while (que.size()) {
        T t = que.front();
        que.pop();
        int cx = get<0>(t);
        int cy = get<1>(t);
        int cd = get<2>(t);
//        cout << cx << "," << cy << "," << cd << endl;
  
        int nx = cx + dx[cd];
        int ny = cy + dy[cd];

//        cout << nx << "," << ny << "," << cd << endl;
        if(0 < nx && nx <= H && 0 < ny && ny <= W && cyx[nx][ny] != '@'){
//            cout << dis[ny][nx][cd] << "," << dis[cx][cy][cd] << endl;
            if (dis[nx][ny][cd] > dis[cx][cy][cd] + 1){
                dis[nx][ny][cd] = dis[cx][cy][cd] + 1;
                que.push(T(nx,ny,cd));
            }
        }
        int plusqc = (cd + 1) % 4;
        int minusqc = (cd + 3) % 4;

        long long turndis = 0;
        if (dis[cx][cy][cd] % K != 0) turndis = dis[cx][cy][cd] - (dis[cx][cy][cd] % K) + K;
        else turndis = dis[cx][cy][cd];

//        cout << dis[cy][cx][plusqc] << "," << dis[cx][cy][cd] << endl;
        if (dis[cx][cy][plusqc] > turndis){
            que.push(T(cx,cy,plusqc));
            dis[cx][cy][plusqc] = turndis;
        }
//        cout << dis[cy][cx][minusqc] << "," << dis[cx][cy][cd] << endl;
        if (dis[cx][cy][minusqc] > turndis){
            que.push(T(cx,cy,minusqc));
            dis[cx][cy][minusqc] = turndis;
        }
    }


    long long turn = INF;
    for (int i = 0;i < 4;i++){
//        cout << i << "=" << dis[X2][Y2][i] << endl;
        if (turn > dis[X2][Y2][i]){
            turn = dis[X2][Y2][i];
        }
    }  
    if (turn < INF){
        if (turn % K != 0) turn = turn - (turn % K) + K;
        turn = turn / K;
        cout << turn << endl;
    }
    else {
        cout << "-1" << endl;
    }

    return 0;
}


Measured memory_bytes: 71540