akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			double S = Double.parseDouble(str);
			S /= 3600;
			int h = (int)Math.floor(S);
			int m = (int)Math.floor((S - h) * 60);
			int s = (int) Math.round((((S - h) * 60) - m) * 60);
			String w = String.valueOf(h) + ":" + String.valueOf(m) + ":" + String.valueOf(s);
			System.out.println(w);
		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}

	}
}

Measured memory_bytes: 17108
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <math.h>

using namespace std;

void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f)
{
  if (rest == 0) {
    f(indexes);
  } else {
    if (s < 0) return;
    recursive_comb(indexes, s - 1, rest, f);
    indexes[rest - 1] = s;
    recursive_comb(indexes, s - 1, rest - 1, f);
  }
}
void foreach_comb(int n, int k, std::function<void(int *)> f)
{
  int indexes[k];
  recursive_comb(indexes, n - 1, k, f);
}

vector<pair<short,short>> v;

int main()
{
    unsigned short N,D;
    cin >> N >> D;
    short X[N][D];
    for(int i=0; i<N; i++){
        for(int j=0; j<D; j++){
            cin >> X[i][j];
        }
    }
    foreach_comb(N, 2, [](int *indexes) {
        v.push_back(make_pair(indexes[0],indexes[1]));
    });
    
    int cnt = 0;
    vector<pair<short,short>>::iterator itr = v.begin();
    while(itr != v.end()){
        //cout << itr->first << ":" << itr->second << endl;
        double tmp = 0.0;
        int a = itr->first;
        int b = itr->second;
        for(int j=0; j<D; j++){
            tmp += (X[a][j]-X[b][j]) * (X[a][j]-X[b][j]);
            //cout << X[a][j] << " - " << X[b][j] << endl;
            //cout << tmp << endl;
        }
        //cout << sqrt(tmp) << endl;
        double x = sqrt(tmp);
        //cout << ceil(x) << endl;
        //cout << floor(x) << endl;
        if(ceil(x) == floor(x)){
            cnt++;
        }
        ++itr;
    }
    cout << cnt << endl; 
    return 0;
}

Measured memory_bytes: 256
n,m= map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
b = [int(input()) for i in range(m)]
c = [0] * n
for i in range(n):
    for j in range(m):
        c[i] += a[i][j] * b[j]
    print(c[i])


Measured memory_bytes: 6020
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define INF 1000000000
#define rep(i,a,b) for (int i=(a);i<(b);i++)
#define rev(i,a,b) for (int i=(a)-1;i>=b;i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef queue<int> qi;
typedef vector<int> vi;
typedef vector<string> vs;
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };

const int M = 123456 * 2;
bool prime[M];

int main() {

	rep(i,0,M) prime[i] = true;
	rep(i,2,sqrt(M)) {
		if(prime[i])
			for(int j = 0; i * (j + 2) < M; j++)
				prime[i *(j + 2)] = false;
	}

	while(true) {
		int n;
		cin >> n;
		if(!n) break;

		if(n == 1) {
			cout << 1 << endl;
			continue;
		}

		int ans = 0;
		rep(i,n+1,2*n) if(prime[i]) ans++;
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1400
n = int(input())
result =10**10
for i in range(1, n):
    A = str(i)
    a_sum = 0
    B = str(n - i)
    b_sum = 0
    for j in range(len(A)):
        a_sum += int(A[j])
    for k in range(len(B)):
        b_sum += int(B[k])
    if a_sum + b_sum <= result:
        result = a_sum + b_sum

print(result)

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

int main() {
	long n,m,a=1;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		a*=(i+1);
		a%=1000000007;
	}
	for(int i=0;i<m;i++){
		a*=(i+1);
		a%=1000000007;
	}
	if(max(n,m)-min(n,m)>1)cout<<0<<endl;
	else if(n==m)cout<<(2*a)%1000000007<<endl;
	else{
		cout<<a<<endl;
	}
	return 0;
}

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

using namespace std;

#define F first
#define S second
#define int long long
#define mpr make_pair 
typedef long long ll;
#pragma GCC optimize("Ofast")

const int maxn = 1e6+10;
const int N = 1e6+5;
const int mod = 998244353;
const int inf = 1e9+10;

int n, m;
bool is[maxn];

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    cin>> n >> m;
    for(int i = 1, x; i <= 2*m; i++)
    {
        cin>> x;
        is[x] ^= 1;
    }

    for(int i = 1; i <= n; i++)
        if(is[i]) return cout<<"NO", 0;
    cout<<"YES";
}





Measured memory_bytes: 512
from collections import Counter

n = int(input())
s = [input() for i in range(n)]
c = []
for i in range(n):
    C = Counter(s[i])
    c.append(C)

ans = ""
for w in [chr(ord('a') + i) for i in range(26)]:
    num = 10 ** 2
    for i in range(n):
        num = min(num, c[i][w])
    ans += w * num
print(ans)

Measured memory_bytes: 3436
from pprint import pprint

n = int(input().strip())
for i in range(n):
    line = input().strip().split()
    if i == 0:
        mat = [int(line[0]), int(line[1])]
    else:
        mat.append(int(line[1]))
#pprint(mat)
dp = [[-999999999] * (n+1) for _ in range(n+1)]
for i in range(n+1):
    dp[i][i] = 0

for i in range(n, 0, -1):
    for j in range(i+1, n+1):
        #for k in range(i, j):
        #    print(i, k, j)
        #    print((i, k), (k+1, j), dp[i][k], dp[k+1][j])
        #    print(dp[i][k], dp[k-1][j], mat[i-1] * mat[k] * mat[j])
        #    assert(dp[i][k] >= 0)
        #    assert(dp[i+j-k][j] >= 0)
        dp[i][j] = min(dp[i][k] + dp[k+1][j] + mat[i-1] * mat[k] * mat[j] for k in range(i, j))
        #print("--")

#pprint(dp)
print(dp[1][n])

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

int pow(int n){

        int ans = 1;
        for(int i=0;i<n;i++){
            ans *= 10;
        }
    return ans;

}


int main()
{
    long long N,bit=0;

    cin >>N;

    vector<string> S;
    string s;

    rep(i,N){
        cin >> s;
        S.push_back(s);
    }

    sort(S.begin(),S.end());

    vector<string> T;
    vector<long long> count;
    T.push_back(S[0]);
    count.push_back(1);

    for(int i=1;i<S.size();i++){
        if(S[i]==S[i-1]){
            count.back()++;
        }else{
            T.push_back(S[i]);
            count.push_back(1);
        }
    }

    long long max=*max_element(count.begin(), count.end());

    rep(i,T.size()){
        if(count[i]==max){
            cout << T[i] <<endl;
        }
    }

    return 0;

}

Measured memory_bytes: 19184
import java.util.*;

public class Main {

   
    public static void main(String[] args) {
      Scanner scanner = new Scanner(System.in);
      String s = scanner.nextLine();
      if(s.charAt(2)  == s.charAt(3) && s.charAt(4) == s.charAt(5)){
          System.out.println("Yes");
      } else{
          System.out.println("No");
      }
    }
    
}


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

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T1, class T2>
ostream &operator<<(ostream &s, pair<T1, T2> P)
{
    return s << '<' << P.first << ", " << P.second << '>';
}
template <class T>
ostream &operator<<(ostream &s, vector<T> P)
{
    for (int i = 0; i < P.size(); ++i)
    {
        if (i > 0)
        {
            s << " ";
        }
        s << P[i];
    }
    return s;
}
template <class T>
ostream &operator<<(ostream &s, vector<vector<T>> P)
{
    for (int i = 0; i < P.size(); ++i)
    {
        s << endl
          << P[i];
    }
    return s << endl;
}
template <class T>
ostream &operator<<(ostream &s, set<T> P)
{
    EACH(it, P) { s << "<" << *it << "> "; }
    return s << endl;
}
template <class T1, class T2>
ostream &operator<<(ostream &s, map<T1, T2> P)
{
    EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; }
    return s << endl;
}
template <class T>
void show(vector<T> v)
{
    for (int i = 0; i < v.size(); i++)
    {
        cerr << v[i] << " ";
    }
    cerr << "\n";
}
typedef long long ll;

map<int, int> mp;
signed main()
{
    int n, p;
    cin >> n >> p;
    string s;
    cin >> s;
    if(p==2 || p==5){
        int ans=0;
        for (int i = 0; i < n; i++)
        {
            if((s[i]-'0') % p == 0) ans+=(ll)i+1;
        }
        cout<<ans<<endl;
        return 0;
    }
  
    reverse(ALL(s));
    cerr<<s<<endl;
    int r=0,d=1;
    int ans=0;
    mp[0]++;
    for (int i = 0; i < n; i++)
    {

     int c=s[i]-'0';
      r=(r+ c*d)%p;
      d = (d * 10) % p;
    //  cerr<<mp[r]<<endl;
      ans+=mp[r];
      mp[r]++;
     // cerr<<r<<endl;
    }
   
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1028
s = input()
t = input()
dp = [[0]*(len(t)+1) for _ in range(len(s)+1)]
for i in range(1, len(s)+1):
    for j in range(1, len(t)+1):
        dp[i][j] = max(dp[i][j], dp[i-1][j])
        dp[i][j] = max(dp[i][j], dp[i][j-1])
        if s[i-1] == t[j-1]:
            dp[i][j] = max(dp[i][j], dp[i-1][j-1]+1)

ans = ""
i = len(s)
j = len(t)
while 0 < i and 0 < j:
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        i -= 1
        j -= 1
        ans += s[i]
print(ans[::-1])

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

int main()
{
	char s[11];
	
	while(scanf("%s", s) != EOF){
		
		int num[10][10];
		for (int i = 0; i < 10; i++){
			num[0][i] = s[i] - '0';
		}
		
		for (int i = 1; i < 10; i++){
			for(int j = 0; j <= 9 - i; j++){
				num[i][j] = num[i-1][j] + num[i-1][j+1];
				if (num[i][j] >= 10){
					num[i][j] -= 10;
				}
			//	printf("  %d\n", num[i][j]);
			}
			//printf("%d\n", i);
		}
		printf("%d\n", num[9][0]);
	}
	return (0);
}

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

int main() {
  int A, B, C, D, L, R;
  
  cin >> A >> B >> C >> D;
  
  L = A + B;
  R = C + D;
  
  if(L > R){
    cout << "Left" << endl;
  } else if(L < R){
    cout << "Right" << endl;
  } else{
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 3604
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 

const ll inf = (ll)(1e17 + 17);
const ll mod = (ll)(1e9 + 7);


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  vll a(2);
  cin >> a[0] >> a[1];
  sort(all(a));
  ll ans = a[1];
  a[1]--;
  sort(all(a));
  ans+= a[1];
  cout << ans << endl;
  return 0;
} //good night.

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int m=2019;
int dp[m];
int main(){
  string s;
  cin>>s;
  int n=s.size();
  int l=s[n-1]-'0';
  dp[l]++;
  int z=1;
  int k;
  for(int i=n-2;i>=0;i--){
    z=(10*z)%m;
    k=(((s[i]-'0')*z)%m+l)%m;
    dp[k]++;
    l=k;
  } 
  ll ans=0;
  for(int i=0;i<2019;i++){
    ans+=(1LL*dp[i]*(dp[i]-1)/2);
  }
  ans+=dp[0];
  cout<<ans;
  return 0;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int main(){
    ll n,m; cin>>n>>m;
    vector<ll> istwice(n+2, 0);
    rep(i,m){
        ll c,d; cin>>c>>d;
        istwice[c]++;
        istwice[d]--;
    }
    rep(i, n+1) istwice[i+1]+=istwice[i];
    ll res=n+1;
    rep(i, n+2){
        if(istwice[i]>0) res+=2;
    }
    cout<<res<<endl;
    return 0;
}


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

int main(){
    int ans = 0;
    string s;
  cin >> s;
    for(int i = 0;i < 4;i++){
        if(s.substr(i,1) == "+"){
            ans++;
        }else{
            ans--;
        }
    }
    cout << ans << endl;
}


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

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

    vector<pair<int, int>> A(N);
    for (auto& x : A) cin >> x.first >> x.second;
    sort(A.begin(), A.end());

    int ans = 0, cnt = 0;
    for (int i = 0; i < N; i++) {
        ans += A[i].first * min(A[i].second, M - cnt);
        cnt += A[i].second;
        if (cnt >= M) break;
    }
    cout << ans << endl;
}


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

int main() {
  int s; cin >> s;
  int a[1100000];
  a[0] = s;

  int i;
  bool flag = false;
  for(i = 1; i < sizeof(a); i++) {
    if(a[i-1]%2 == 0) a[i] = a[i-1] / 2;
    else a[i] = 3*a[i-1] + 1;
    for(int j = 0; j < i; j++) {
      if(a[i] == a[j]) {
        flag = true;
        break;
      }
    }
    if(flag) break;
  }
  cout << i + 1 << endl;
}


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

int main() {
    const double PI  =3.141592653589793238463;

    ios::sync_with_stdio(false);
    cin.tie(0);
    double R, ans = 0;
    cin>>R;
    ans = 2*PI*R;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3804
#ifndef COMPETITIVE_GRAPH_H
#define COMPETITIVE_GRAPH_H

#include <map>
#include <set>
#include <utility>
#include <queue>

template<typename T>
class djikstra {
private:
    std::map<T, std::set<std::pair<T, T>>> path; //src dst cost
    std::map<T, T> dist; //dst cost
public:
    void compute(T start);

    void add_path(T src, T dst, T cost);

    T get_dist(T dst);
};

#endif //COMPETITIVE_GRAPH_H

#ifndef COMPETITIVE_NIKLIB_H
#define COMPETITIVE_NIKLIB_H

#ifdef BUILT_LOCAL

#include "graph.h"

#endif

#endif //COMPETITIVE_NIKLIB_H

#ifdef BUILT_LOCAL

#include "niklib.h"

#endif

template<typename T>
void djikstra<T>::compute(T start) {
    dist.clear();
    dist[start] = 0;
    std::priority_queue<std::pair<T, T>, std::deque<std::pair<T, T>>, std::greater<>> q;
    for (auto &e:path[start]) q.push(std::make_pair(e.second, e.first));
    while (!q.empty()) {
        auto c = q.top();
        q.pop();
        if (dist.find(c.second) != dist.end()) continue;
        dist[c.second] = c.first;
        for (auto &e:path[c.second]) {
            if (dist.find(e.first) != dist.end()) continue;
            q.push(std::make_pair(c.first + e.second, e.first));
        }
    }
}

template<typename T>
void djikstra<T>::add_path(T src, T dst, T cost) {
    path[src].insert(std::make_pair(dst, cost));
}

template<typename T>
T djikstra<T>::get_dist(T dst) {
    return dist.find(dst) == dist.end() ? -1 : dist[dst];
}

template
class djikstra<long long>;

#ifdef BUILT_LOCAL

#include "niklib.h"

#endif

#include <iostream>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>
#include <map>
#include <set>
#include <list>

using namespace std;

typedef long long ll;
constexpr ll mod = 1000000007;

int main() {
    int n, m, l, r, c;
    djikstra<ll> d;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> l >> r >> c;
        d.add_path(l, r, c);
    }
    for (int i = 1; i < n; i++) {
        d.add_path(i + 1, i, 0);
    }
    d.compute(1);
    cout << d.get_dist(n) << endl;
}

Measured memory_bytes: 27776
#include <bits/stdc++.h>
using namespace std;
typedef int64_t Int;
#define dump(x) cout << (x) << '\n'
Int mod = 1e9+7;

int main() {
    Int n;
    string s;
    cin >> n >> s;
    vector<Int> a(n + 2, 0), b(n + 2, 0);
    for (Int i = 1; i <= n; i++) {
        if (s[i - 1] == '#') {
            a[i]++;
        }
        else {
            b[i]++;
        }
    }
    for (Int i = 1; i <= n; i++) a[i + 1] += a[i];
    for (Int i = n; i > 0; i--) b[i - 1] += b[i];
    Int mi = 1e9;
    for (Int i = 1; i <= n; i++) {
        if (a[i - 1] + b[i + 1] < mi) mi = a[i - 1] + b[i + 1];
    }
    dump(mi);
    return 0;
}

Measured memory_bytes: 3716
import math

def P(n, r):
    if n < r:
        return 0
    return math.factorial(n)//math.factorial(n-r)


def C(n, r):
    return P(n, r)//math.factorial(r)

n, m = map(int, input().split())

print(C(n, 2) + C(m, 2))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
    int X;
    cin >> X;
    const int x = 1e9 + 7;
    for(int i = X;i <= x;++i){
        int judge = 0;
        for(int j = i;j > 1;j--){
            if(i % j == 0 && judge == 0){
                judge++;
            }else if(i % j == 0 && judge == 1){
                judge++;
                break;
            }
        }
        if(judge == 1){
            cout << i << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::io::{BufWriter, Write};

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    input!(
        n: usize,
        p: [usize; n],
    );

    let mut cnt = 0;

    for i in 0..n {
        if p[i] != i+1 {
            cnt += 1;
        }
    }
    if cnt == 2 || cnt == 0 {
        println!("YES");
    }
    else {
        println!("NO");
    }
}

fn main() {
    let stack_size = 1 << 28;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
import sys
from fractions import gcd

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

A, B = lr()
g = gcd(A, B)

def prime_factorize(n): # Nの素因数分解
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

G = prime_factorize(g)
# 互いに素なので小さい順にgreedyに選ぶ
used = set([1])
for x in G:
    for y in used:
        if gcd(x, y) != 1:
            break
    else:
        used.add(x)

print(len(used))


Measured memory_bytes: 5076
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;
typedef pair<long long int, pll> lpll;


const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 

long long int W,H,x,y,res[200200]={},tmp=0;
pll ba[200200];
string S;

int main(){
    cout << fixed << setprecision(18);
    cin>>W>>H>>x>>y;
    if(W==2*x&&H==2*y){
        cout<<W*H/2.0<<" "<<1<<endl;
    }else{
        cout<<W*H/2.0<<" "<<0<<endl;
    }
}




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

typedef long long LL;

int main (int argc, char **argv)
{
  LL n = 0;
  LL *a = 0;
  LL *b = 0;
  LL i = 0;
  LL ans = 0;

  scanf("%lld", &n);

  a = (LL *)malloc((n + 1) * sizeof(LL));
  b = (LL *)malloc(n * sizeof(LL));

  for(i = 0; i < n + 1; i++)
  {
    scanf("%lld", &a[i]);
  }
  for(i = 0; i < n; i++)
  {
    scanf("%lld", &b[i]);
  }

  for(i = 0; i < n; i++)
  {
    if(a[i] < b[i])
    {
      ans += a[i];
      b[i] -= a[i];
      a[i] = 0;
      if(a[i + 1] < b[i])
      {
        ans += a[i + 1];
        b[i] -= a[i + 1];
        a[i + 1] = 0;
      }
      else
      {
        ans += b[i];
        a[i + 1] -= b[i];
        b[i] = 0;
      }
    }
    else
    {
      ans += b[i];
      a[i] -= b[i];
      b[i] = 0;
    }
  }

  printf("%lld\n", ans);
  free(a);
  free(b);

  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	ll n,m;
	cin >> n>>m;
	ll sumx = 0,sumy = 0;
	REP(i,n){
		ll x;cin>>x;
		sumx += (2*i-n+1)*x;
		sumx %= MOD;
	}
	REP(j,m){
		ll y;cin >> y;
		sumy += (2*j-m+1)*y;
		sumy %= MOD;
	}
	cout << sumx%MOD*sumy%MOD << endl;
  return 0;
}


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

using namespace std;

int main() {

	vector<int> dice(7, 0);
	vector<int> newdice(7, 0);
	cin >> dice[1] >> dice[2] >> dice[3]>> dice[4] >> dice[5] >> dice[6];

	int n;
	cin >> n;
	int a, b;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		if ((a == dice[4] && b == dice[2])
			|| (a == dice[2] && b == dice[3])
			|| (a == dice[3] && b == dice[5])
			|| (a == dice[5] && b == dice[4])) {
			cout << dice[1] << endl;
		}
		if ((a == dice[1] && b == dice[4])
			|| (a == dice[4] && b == dice[6])
			|| (a == dice[6] && b == dice[3])
			|| (a == dice[3] && b == dice[1])) {
			cout << dice[2] << endl;
		}
		if ((a == dice[1] && b == dice[2])
			|| (a == dice[2] && b == dice[6])
			|| (a == dice[6] && b == dice[5])
			|| (a == dice[5] && b == dice[1])) {
			cout << dice[3] << endl;
		}
		if ((a == dice[1] && b == dice[5])
			|| (a == dice[5] && b == dice[6])
			|| (a == dice[6] && b == dice[2])
			|| (a == dice[2] && b == dice[1])) {
			cout << dice[4] << endl;
		}
		if ((a == dice[1] && b == dice[3])
			|| (a == dice[3] && b == dice[6])
			|| (a == dice[6] && b == dice[4])
			|| (a == dice[4] && b == dice[1])) {
			cout << dice[5] << endl;
		}
		if ((a == dice[2] && b == dice[4])
			|| (a == dice[4] && b == dice[5])
			|| (a == dice[5] && b == dice[3])
			|| (a == dice[3] && b == dice[2])) {
			cout << dice[6] << endl;
		}

	}
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll x,y;
	vpll v;
	while(1){
		cin >> x >> y;
		if(x==0 && y==0) break;
		v.pb(m_p(min(x,y),max(x,y)));
	}
	rep(i,SIZE(v)) cout << v[i].first << " " << v[i].second << endl;
	return 0;
}


Measured memory_bytes: 3084
/* Author: Rennan Rocha
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>
#define vpll vector<pll>

#define MOD 1000000007

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order(); order_of_key();

ll add(ll a, ll b) {
    return ((a % MOD) + (b % MOD)) % MOD;
}

ll mul(ll a, ll b) {
    return ((a % MOD) * (b % MOD)) % MOD;
}

ll sub(ll a, ll b) {
    ll resp = ((a % MOD) - (b % MOD)) % MOD;
    if(resp < 0) resp += MOD;
    return resp;
}

ll inv2 = 500000004;
int main() {
    ios_base::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;

    ll ans = 0;
    for(ll i = k; i <= n+1; i++) {
        ll soma = mul(mul(sub(i, 1), i), inv2); 
        ll mini = soma;
        ll maxi = sub(mul(i, n), soma);
        ans = add(ans, add(sub(maxi, mini), 1));
    }
    cout << ans << endl;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int N;
  cin>>N;
  VEC<LL>H(N);
  REP(i,0,N)cin>>H[i];
  int ans =0;
  int cnt =0;
  REP(i,0,N-1){
    // DUMP(H[i], cnt);
    if(H[i]>=H[i+1]){
      cnt++;
    }else{
      ans = max(ans,cnt);
      cnt=0;
    }
  }
  ans=max(ans, cnt);
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	set<string> s;
	int i,n;
	string c;
	scanf("%d",&n);
	for(i=0;i<n;++i)
	{
		cin >> c;
		s.insert(c);
	}
	printf("%d",s.size());
}


Measured memory_bytes: 19376
package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
	)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		table := make([]bool, 10001)
		now := make([]int, 10001)
		count := make([]int, 10001)
		a, _ := strconv.Atoi(scanner.Text())
		if a == 0 {
			break
		}
		index := 0
		for i := 1; i < a; i++ {
			val := i*i%a
			if !table[val] {
				table[val] = true
				now[index] = val
				index++
			}
		}
		for i := 0; i < index; i++ {
			for j := i+1; j < index; j++ {
				t := now[i] - now[j]
				if t < 0 {
					t += a
				}
				if t > (a-1)/2 {
					t = a - t
				}
				count[t]++
			}
		}
		for i := 1; i <= a/2; i++ {
			fmt.Println(count[i]*2)
		}
	}
}


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

#define rep(i,n) for (int i=0; i < (n); ++i)
using ll = long long ;
using namespace std;
const int INF = 1001001001;

int main() {

    int x ;
    cin >> x ;

    ll sum = 0 ;
    int i = 1 ;
    while(1){
        sum+= i ;
        if(sum>=x){
            cout << i << endl ;
            break ;
        }
        ++i ;
    }
    return 0 ;
}

Measured memory_bytes: 3640
#include <math.h>
// r:グー s:チョキ p:パー
int main(){
  int N,K,R,S,P,i;
  char T[100002];
  scanf("%d %d",&N,&K);
  scanf("%d %d %d",&R,&S,&P);
  scanf("%s",T);
  int A[100002] = {0};
  int tmp = 0;
  for(i=0; i<N; i++){
    // 全部勝った場合の得点を計算
    if(T[i]=='r'){
      if(i>=K&&T[i-K]=='r'){
		T[i] = '0';
      }else{
        tmp += P;
        A[i] = tmp; 
      }
    }else if(T[i]=='s'){
      if(i>=K&&T[i-K]=='s'){
		T[i] = '0';
      }else{
        tmp += R;
        A[i] = tmp; 
      }
    }else if(T[i]=='p'){
      if(i>=K&&T[i-K]=='p'){
        T[i] = '0';
      }else{
        tmp += S;
        A[i] = tmp;
      }
    }
  }
  printf("%d\n",tmp);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

const int MAX_N=100000;

ll dp[3][MAX_N];

int main(void){
    int n;
    cin >> n;
    REP(i,n)
        cin >> dp[0][i] >> dp[1][i] >> dp[2][i];
    FOR(i,1,n){
        dp[0][i]+=max(dp[1][i-1],dp[2][i-1]);
        dp[1][i]+=max(dp[2][i-1],dp[0][i-1]);
        dp[2][i]+=max(dp[0][i-1],dp[1][i-1]);
    }
    cout << max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1])) << endl;

    return 0;
}

Measured memory_bytes: 5920
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	int K; cin >> K;
	rep(i,K) cout << "ACL";
	cout << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define LL long long
#define Max 100005
const LL mod=1e9+7;
const LL LL_MAX=9223372036854775807;
using namespace std;
int main()
{
    int a,b,c,d,e,k;
    scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&k);
    if(abs(a-b)<=k && abs(a-c)<=k && abs(a-d)<=k && abs(a-e)<=k && abs(b-c)<=k && abs(b-d)<=k && abs(b-e)<=k &&
       abs(c-d)<=k && abs(c-e)<=k && abs(d-k)<=k )
        printf("Yay!\n");
    else
        printf(":(\n");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
using namespace std;
using ll = long long;


//eating l cakes of index<=k

int main(void){
    int N, M;
    ll x[1001][3];
    cin >> N >> M;
    for(int i = 0; i< N; i++){
        for(int j = 0; j < 3; j++) cin >> x[i][j];
    }

    ll res = 0;

    for(int i = 0; i < 8; i++){
        ll sum[1001] = {0};
        for(int j = 0; j < N; j++){
            for(int k = 0; k < 3; k++){
                if((i&(1<<k)) != 0){
                    sum[j] += x[j][k];
                }else{
                    sum[j] -= x[j][k];
                }
            }
        }

        sort(sum, sum+N, greater<ll>());
        ll y = accumulate(sum, sum+M, 0LL);
        res = max(res, y);
    }

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

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define FOR(i, l, r) for(int i = l; i <= r; ++i)
using namespace std;

int n, m, tot;
int a[110];

int main()
{
    scanf("%d%d", &n, &m);
    FOR(i, 1, m)
    {
        scanf("%d", &a[i]);
        if (a[i] & 1) ++tot;
    }
    if (tot > 2) {puts("Impossible"); return 0;}

    if (m == 1)
    {
        if (n == 1) printf("1\n1\n1\n"); else
            printf("%d\n2\n1 %d\n", n, n - 1);
        return 0;
    }

    FOR(i, 1, m) if (a[i] & 1) {swap(a[i], a[1]); break;}
    FOR(i, 2, m) if (a[i] & 1) {swap(a[i], a[m]); break;}

    FOR(i, 1, m) printf("%d ", a[i]); puts("");
    if (a[1] == 1) printf("%d\n", m - 1); else printf("%d\n%d ", m, a[1] - 1);
    FOR(i, 2, m - 1) printf("%d ", a[i]);
    printf("%d\n", a[m] + 1);

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
typedef pair<int, vector<int> > P;
map<P, int> memo;
int dfs(int k, vector<int>& cur, const vector<int>& s, map<int, int>& cnt){
  int L = cur.size(), N = s.size();
  P p(k, cur);
  if(memo.count(p)) return memo[p];
  int& res = memo[p];
  res = INF;
  int S = s[k];
  for(int i = L - 1; i >= 0; i--){
    if(S >> i & 1) break;
    if(cur[i] != 0) return res;
  }
  if(k + 1 == N) return res = 0;
  int use = cnt[S];
  for(int i = 0; i < L; i++) if(S >> i & 1) use = min(use, cur[i]);
  vector<int> tmp = cur;
  for(int i = 0; i <= use; i++){
    for(int j = 0; j < L; j++) if(S >> j & 1) cur[j] -= i;
    res = min(res, dfs(k + 1, cur, s, cnt) + i);
    cur = tmp;
  }
  //printf("dfs(S = %d) : ", S); REP(i, L) cout << cur[i] << " "; cout << endl;
  return res;
}
int main(){
  int H, W;
  while(cin >> H >> W && H){
    memo.clear();
    map<int, int> cnt;
    vector<int> s;
    vector<string> grid(H);
    REP(y, H) cin >> grid[y];
    vector<int> mx, my;
    vector<int> cur;
    REP(y, H)REP(x, W)if(isdigit(grid[y][x])){
      mx.push_back(x);
      my.push_back(y);
      cur.push_back(grid[y][x] - '0');
    }
    int L = mx.size();
    REP(y, H)REP(x, W)if(grid[y][x] != '.'){
      int S = 0;
      REP(i, L)if(abs(mx[i] - x) <= 1 && abs(my[i] - y) <= 1){
        S |= 1 << i;
      }
      cnt[S] += 1;
      if(cnt[S] == 1) s.push_back(S);
    }
    s.push_back(0); //last
    sort(s.begin(), s.end());
    reverse(s.begin(), s.end());
    cout << dfs(0, cur, s, cnt) << endl;
  }
  return 0;
}

Measured memory_bytes: 4616
#include <cstdio>
#include <cstring>
#define ll long long int
ll mabs(ll x)
{
	if(x<0) return -x;
	return x;
}
ll X, K, D, ans;
int main()
{
	scanf("%lld%lld%lld", &X, &K, &D);
	if(X<0)
	    X = -X;
	if(X>=0)
	{
		ll k = (X/D)+1;
		ll a = X-k*D, b = X-k*D+D;
		if(K>=k)
		{
			K -= k;
			if(K%2==0)
		    	printf("%lld\n", mabs(a));
		    else
		        printf("%lld\n", mabs(b));
		}
		else
		{
			printf("%lld\n", X-K*D);
		}
	}
	return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define rep(i,a,n) for(int i=(a);i<=(n);++i)
#define dep(i,a,n) for(int i=(a);i>=(n);--i)
#define eps 1e-8
#define pi 3.1415926535897
#define sqr(x) ((x)*(x))
#define MAX(a,b) a=max(a,b)
#define MIN(a,b) a=min(a,b)
#define SZ(x) ((int)(x).size())
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define POSIN(x,y) (1<=(x)&&(x)<=n&&1<=(y)&&(y)<=m)
#define all(x) (x).begin(),(x).end()
#define COUT(S,x) cout<<fixed<<setprecision(x)<<S<<endl
#define buli(x) (__builtin_popcountll(x))
#define bur0(x) (__builtin_ctzll(x))
#define bul2(x) (63-__builtin_clzll(x))
#define pw(x) ((ll(1))<<(x))
#define upmo(a,b) (((a)=((a)+(b))%mo)<0?(a)+=mo:(a))
#define mmo(a,b) (((a)=1ll*(a)*(b)%mo)<0?(a)+=mo:(a))
#define y0 y0z
#define y1 y1z
#define yn ynz
#define j0 j0z
#define j1 j1z
#define jn jnz
#define tm tmz
#ifdef LOCAL
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...) 
#endif
typedef long long ll;
typedef double lf;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<lf,lf> pff;
typedef complex<double> CD;
const int inf=0x3f3f3f3f;
const int mo=1000000007;
inline void gn(long long&x){
	int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
	while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
inline void gn(double&x){double t;scanf("%lf",&t);x=t;}
inline void gn(long double&x){double t;scanf("%lf",&t);x=t;}
template<class T1,class T2>inline void gn(T1&r,T2&s){gn(r),gn(s);}
template<class T1,class T2,class T3>inline void gn(T1&r,T2&s,T3&t){gn(r),gn(s),gn(t);}
template<class T1,class T2,class T3,class T4>inline void gn(T1&r,T2&s,T3&t,T4&u){gn(r),gn(s),gn(t),gn(u);}
inline void gs(char *s){scanf("%s",s);}
inline void gc(char &c){while((c=getchar())>126 || c<33);}
inline void pc(char c){putchar(c);}
const int DX[]={1,0,-1,0},DY[]={0,1,0,-1};
ll powmod(ll a,ll b) {ll res=1;a%=mo;for(;b;b>>=1){if(b&1)res=res*a%mo;a=a*a%mo;}return res;}
ll powmod(ll a,ll b,ll mo) {ll res=1;a%=mo;for(;b;b>>=1){if(b&1)res=res*a%mo;a=a*a%mo;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//*******************************************

const int N=111111,M=111111;
int l,m,n,t,C;
int main(){
#ifdef LOCAL
	freopen("B.in","r",stdin);//freopen("B.out","w",stdout);
#endif
	int a,b,c,k;
	scanf("%d%d%d%d",&a,&b,&c,&k);
	rep(i,1,k){
		if(b<=a)b*=2;else c*=2;
	}
	puts(c>b&&b>a?"Yes":"No");
	return 0;
}


Measured memory_bytes: 3760
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.AGC_030
{
    class B
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            long[] ln = ReadLongs();
            long l = ln[0];
            int n = (int)ln[1];
            var xs = new long[n + 1];
            var xSums = new long[n + 1];
            for (int i = 1; i <= n; i++)
            {
                xs[i] = ReadLong();
                xSums[i] = xSums[i - 1] + xs[i];
            }
            var ys = new long[n + 1];
            var ySums = new long[n + 1];
            for (int i = 1; i <= n; i++)
            {
                ys[i] = l - xs[n + 1 - i];
                ySums[i] = ySums[i - 1] + ys[i];
            }

            long res = 0;
            for (int i = 0; i <= n; i++)
            {
                int r = n - i;
                long cnt = 0;
                long ll = 0;
                if (i > 0)
                {
                    cnt = Math.Min(i - 1, r);
                    ll += (xSums[i - 1] - xSums[i - 1 - cnt]) * 2;
                    ll += (ySums[r] - ySums[r - cnt]) * 2;
                    ll += xs[i];
                }

                long lr = 0;
                cnt = Math.Min(i, r);
                lr += (xSums[i] - xSums[i - cnt]) * 2;
                lr += (ySums[r] - ySums[r - cnt]) * 2;
                lr -= xs[i];

                long rl = 0;
                cnt = Math.Min(i, r);
                rl += (xSums[i] - xSums[i - cnt]) * 2;
                rl += (ySums[r] - ySums[r - cnt]) * 2;
                rl -= ys[r];

                long rr = 0;
                if (r > 0)
                {
                    cnt = Math.Min(i, r - 1);
                    rr += (xSums[i] - xSums[i - cnt]) * 2;
                    rr += (ySums[r - 1] - ySums[r - 1 - cnt]) * 2;
                    rr += ys[r];
                }
                res = Math.Max(res, Math.Max(Math.Max(ll, lr), Math.Max(rl, rr)));
            }
            Console.WriteLine(res);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

int main()
{
  int k, s;
  cin >> k >> s;

  int cnt = 0;

  for(int i = 0; i <= k; i++){
    for(int j = 0; j <= k; j++){

      int sij = s - i - j;
      if(i + j + sij == s && sij <= k && sij >= 0) cnt++;

    }
  }

  cout << cnt << endl;

  return 0;

}



Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
#define int long long
signed main(){
  string s,t="";
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(i<s.size()-1&&s[i]=='B'&&s[i+1]=='C'){
      t+="X";
      i++;
    }else{
      t+=s[i];
    }
  }
  int n=t.size(),right=0,ans=0;
  for(int left=0;left<n;left++){
    right=left;
    int cntX=0;
    while(right<n&&(t[right]=='A'||t[right]=='X')){
      if(t[right]=='X'){
        ans+=right-(left+cntX);
        cntX++;
      }
      right++;
    }
    if(left<right)  left=right-1;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 776