akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <assert.h>
#include <algorithm>
#include <string>

int64_t calc_num_putty(int64_t level, int64_t* length, int64_t* numP, int64_t offset){
    if(level == 1){
        if(offset == 0) return 0;
        else if(offset == 1) return 0;
        else if(offset == 2) return 1;
        else if(offset == 3) return 2;
        else return 3;
    }

    int64_t sum = 0;
    if(offset > length[level] / 2 + 1){
        sum = (numP[level] - 1) / 2 + 1;
        sum += calc_num_putty(level-1, length, numP, offset - length[level] / 2 - 1);
        return sum;
    }
    else if(offset == length[level] / 2 + 1){
        sum = (numP[level] - 1) / 2 + 1;
        return sum;
    }
    else{
        sum = calc_num_putty(level-1, length, numP, offset - 1);
        return sum;
    }
}

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

    int64_t N, X;
    std::cin >> N >> X;
    int64_t length[N+1];
    length[0] = 1;
    int64_t numP[N+1];
    numP[0] = 1;
    for(int32_t i = 1; i <= N; i++){
        length[i] = length[i-1] * 2 + 3;
        numP[i] = numP[i-1] * 2 + 1;
    }
    int64_t res = 0;
    res = calc_num_putty(N, length, numP, X);

    std::cout << res;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define sz(x) ((int)x.size())

const int mod = 1000000007;
vector<int> a(100005), dp(100005, 0), dp2(100005, 0), &od = dp, &nw = dp2;

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    od[0] = 1;
    int n, k;
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    for(int i = 1; i <= n; i++)
    {
        int sum = 0;
        for(int j = 0; j <= k; j++)
        {
            sum += od[j];
            sum %= mod;
            if(j-a[i]-1 >= 0)
                sum -= od[j-a[i]-1], sum += mod, sum %= mod;
            nw[j] = sum;
        }
        swap(od, nw);
    }
    cout << od[k] << endl;
}

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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


int main()
{
    ll A,B,K;
    cin >> A >> B >> K;
    set<ll> ans;

    REP(i,A,A+K) ans.insert(min(B,(ll)i));
    rep(i,K) ans.insert(max(A, B-K+1+i));

    for(set<ll>::iterator itr = ans.begin(); itr != ans.end(); itr++) cout << *itr << endl;
}


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

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;

#define VECTOR(a) VECTOR_((a), sizeof(a) / sizeof(a[0]))

template <typename T>
std::vector<T> VECTOR_(T *array, std::size_t size) {
  return std::vector<T>(array, array + size);
}

int main(){
	int m[] = {33,1111,15,132,63,231,36};
	for(int a[8]; cin >> a[0]; ) {
		rep(i, 7) cin >> a[i + 1];
		rep(i, 8) {
			int b = 0;
			rep(j, 10) {
				if(a[i] % 10) b += (1 << j);
				a[i] /= 10;
			}
			a[i] = b;
		}
		for(; ; ) {
			bool flg = false;
			rep(j, 8) flg |= a[j] & 1;
			if(!flg) rep(j, 8) a[j] >>= 1;
			else break;
		}
		int k = 0;
		rep(i, 8) if(a[i] != 0) {
			k = k * 10 + a[i];
		}
		rep(i, 7) if(m[i] == k) cout << (char)('A' + i) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#!/usr/bin/env python3
from sys import stdin

def solve():
    n = int(stdin.readline().strip())

    maxi = 0
    cost = 0
    for i in range(n):
        item = int(stdin.readline().strip())
        cost += item
        if item>maxi:
            maxi = item
    cost -= maxi//2
    print(cost)

solve()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

signed main() {
  ll A, B;
  cin >> A >> B;
  if (A + B == 3) {
    COUT(3);
    return 0;
  }
  if (A + B == 4) {
    COUT(2);
    return 0;
  }
  if (A + B == 5) {
    COUT(1);
    return 0;
  }
  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++)
using ll = long long;
using ld = long double;
const ll ATCODER_AMARI = 1000000007; //10^9 + 7
const ll INF = 10000000000000;

//階乗関数
ll factorial(ll k){
  ll sum = 1;
  for(int i = 1 ; i < k + 1; i++) {
    sum *= i;
    sum = sum % ATCODER_AMARI;
  }
  return sum;
}

int main() {
  string s; cin >> s;
  rep(i,3){
    cout << s.at(i);
  }
  cout << endl;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define pb(a) push_back(a)
using namespace std;
typedef long long LL;

int main(){
    vector<string> k = {
        "",
        ".,!? ",
        "abc",
        "def",
        "ghi",
        "jkl",
        "mno",
        "pqrs",
        "tuv",
        "wxyz"
    };
    int n;
    cin >> n;
    rep(i,n){
        string s;
        cin >> s;
        string ans = "";
        int ct = 0, now = 0;
        rep(j, s.size()){
            int x = s[j]-'0';
            if(x == 0){
                if(now == 0) continue;
                ans += k[now][ct%k[now].size()];
                now = 0;
            }else{
                if(now == x){
                    ct++;
                }else{
                    now = x;
                    ct = 0;
                }
            }
        }
        cout << ans << endl;
    }
            
}



Measured memory_bytes: 3012
#include<bits/stdc++.h>
#define mo 1000000007
#define add(a,b) ((a+b>=mo)?(a+=b-mo):(a+=b))
using namespace std;
vector <pair<int,int> >vec[333];
int f[2][3][333][333];
inline bool legal(int i,int j,int k,int l)
{
	for (int kk=0;kk<vec[i].size();kk++)
	{
		int lim=vec[i][kk].first,d=vec[i][kk].second;
		if ((int)(k>=lim)+(int)(l>=lim)+1!=d) return false;
	}
	return true;
}
int main()
{
	int n,m;scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++)
	{
		int l,r,k;scanf("%d%d%d",&l,&r,&k);
		if ((r==1)&&(k!=1)) {printf("0\n");return 0;}
		vec[r].push_back(make_pair(l,k));
	}
	// r=1
	f[1][0][0][0]=f[1][1][0][0]=f[1][2][0][0]=1;
	for (int i=1;i<n;i++)
	{
		//cout<<i<<endl;
		memset(f[!(i&1)],0,sizeof(f[!(i&1)]));
		for (int j=0;j<=2;j++)
		for (int k=0;k<i;k++)
		for (int l=0;l<i;l++) if (f[i&1][j][k][l])
		{
			
			int j1=(j==2)?0:(j+1),j2=(j==0)?2:(j-1);
				//if  ((i==2)&&(j==2)&&(k==1)&&(l==0)) cout<<i+1<<' '<<j2<<' '<<i<<' '<<k<<endl;		
			add(f[!(i&1)][j][k][l],f[i&1][j][k][l]);//cout<<i+1<<' '<<j1<<' '<<l<<' '<<i<<endl;
			add(f[!(i&1)][j1][l][i],f[i&1][j][k][l]);//cout<<i+1<<
			add(f[!(i&1)][j2][i][k],f[i&1][j][k][l]);
		}
		for (int j=0;j<=2;j++)
		for (int k=0;k<i+1;k++)
		for (int l=0;l<i+1;l++)
			if (!legal(i+1,j,k,l)) f[!(i&1)][j][k][l]=0;
	}
	int ans=0;
	for (int j=0;j<=2;j++)
	for (int k=0;k<n;k++)
	for (int l=0;l<n;l++)
	{
		ans+=f[n&1][j][k][l];
		if (ans>=mo) ans-=mo;
	}
	cout<<ans<<endl;
	//cout<<legal(3,1,2,1)<<endl;
}
		

Measured memory_bytes: 2816
#include<iostream>
#include<map>
#include<queue>
#define rep(i,a) for(int i=0;i<a;i++)
using namespace std;
typedef pair<int,int> pii;
long long dp[2010][2010]={0},in[2020],n,o;
queue<pii>q;
int main(){
	cin>>n;rep(i,n)cin>>in[i];
	rep(i,n)dp[i][1]=in[i],q.push(pii(i,1));
	while(!q.empty()){
		pii r=q.front();q.pop();
		int a=r.first,b=r.second,s=a-1,t=(s+1+b)%n,w;
		if(s==-1)s=n-1;
		rep(i,2){
			if(b%2&&in[s]<in[t])s=a;
			w=b%2?0:in[(i?t:s)];
			if(dp[s][++b]<dp[a][b-1]+w){
				dp[s][b]=dp[a][b-1]+w;
				if(b!=n)q.push(pii(s,b));
			}
			if(--b%2==0)s=a;
		}
	}
	rep(i,n)o=max(o,dp[i][n]);
	cout<<o<<endl;
}

Measured memory_bytes: 32668
#include<cstdio>
 
int main(){
    int sp=0;
    int tn=0;
    int n=0;
     
    int price, num;
    
    while( scanf("%d,%d",&price, &num) != EOF) {
    	
        sp += price * num;
        tn += num;
        n++;
        
    }
    printf( "%d\n%d\n", sp, (int)((double) tn / n + 0.5));
}


Measured memory_bytes: 2580
#!/usr/bin/env python3
import sys


def solve(N: int, P: "List[int]"):
    ans = 1
    m = P[0]
    for Pi in P[1:]:
        if Pi <= m:
            m = Pi
            ans += 1
    print(ans)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    P = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, P)

if __name__ == '__main__':
    main()


Measured memory_bytes: 27520
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
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;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937_64 mt64(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/

double a, b, c, d, e, f;
double dis(double x, double y, double x_, double y_) {
	return sqrt(pow(abs(x - x_), 2.) + pow(abs(y - y_), 2.));
}
double heron(double a, double b, double c) {
	double s = (a + b + c) / 2.;
	return sqrt(s * (s - a) * (s - b) * (s - c));
}
signed main() {
	cin >> a >> b >> c >> d >> e >> f;
	double ok = 0., ng = 5000.;
	double disa = dis(a, b, c, d), disb = dis(c, d, e, f), disc = dis(e, f, a, b);
	if (disa > disb)swap(disa, disb);
	if (disc > disb)swap(disc, disb);
	double S = heron(disa, disb, disc);
	double H = S * 2. / disb;
	rep(i, 1000) {
		double r = (ok + ng) / 2.;
		double men = 2 * r * r + (disb - 2. * r) * r / 2.;
		men += disa * r / 2. + disc * r / 2.;
		men += 2. * r * (H - r) / 2.;
		if (men <= S)ok = r;
		else ng = r;
	}
	printf("%.12lf\n", ok);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
     int n;
     cin>>n;
     int cnt=0;
     bool ok=false;
     for(int i=0;i<n;i++)
     {
         int x,y;
         cin>>x>>y;
         if(x==y){cnt++;}
         else cnt=0;
         if(cnt>=3){ok=true;}
     }
     if(ok){cout<<"Yes"<<endl;}
     else {cout<<"No"<<endl;}
}


Measured memory_bytes: 3652
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String s = scan.next();
        char[] steps = s.toCharArray();
        if (even(steps)&&odd(steps)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
    private boolean even(char[] steps) {
        for (int i = 1; i <= steps.length; i++) {
            if (i % 2 == 1) {
                continue;
            }
            if (steps[i-1] == 'L') {
                continue;
            }
            if (steps[i-1] == 'U') {
                continue;
            }
            if (steps[i-1] == 'D') {
                continue;
            }
            return false;
        }
        return true;
    }
    private boolean odd(char[] steps) {
        for (int i = 1; i <= steps.length; i++) {
            if (i % 2 == 0) {
                continue;
            }
            if (steps[i-1] == 'R') {
                continue;
            }
            if (steps[i-1] == 'U') {
                continue;
            }
            if (steps[i-1] == 'D') {
                continue;
            }
            return false;
        }
        return true;
    }
}


Measured memory_bytes: 21972
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, C = MAP()

for i in range(1, B+1):
    amari = i * A % B
    if amari == C:
        print("YES")
        exit()
print("NO")


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

const int MX = 10;
int C[10][10];
const int MAX_H = 202;
int A[MAX_H][MAX_H];

//全点対最短経路問題(ワーシャル・フロイド法)でi -> jへ変換する最小コスト(最短経路)を求める
void warshall_floyd() {
    for(int k = 0; k < MX; ++k) 
        for(int i = 0; i < MX; ++i) 
            for(int j = 0; j < MX; ++j) 
                C[i][j] = min(C[i][j], C[i][k] + C[k][j]);
}

int main()
{
    int H, W;
    cin >> H >> W;
    for(int i = 0; i < MX; ++i)
        for(int j = 0; j < MX; ++j) cin >> C[i][j];
    
    for(int i = 0; i < H; ++i) 
        for(int j = 0; j < W; ++j) cin >> A[i][j];
    
    warshall_floyd();

    ll res = 0;
    for(int i = 0; i < H; ++i) {
        for(int j = 0; j < W; ++j) {
            if(A[i][j] != -1)
                res += C[A[i][j]][1];
        }
    }

    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define M 100005
int n,A[M],B[M],ans;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>A[i];
	B[++ans]=A[n];
	for(int i=n-1;i>=1;i--){
		if(B[ans]<=A[i])B[++ans]=A[i];
		else {
			int l=1,r=ans,res;
			while(l<=r){
				int mid=l+r>>1;
				if(B[mid]<=A[i])l=mid+1;
				else r=mid-1,res=mid;
			}
			B[res]=A[i];
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
n = int(input())
a = []
a.append([0,0])
for i in range(n):
    in1, in2 = map(str, input().split())
    a.append([float(in1),in2])

ans = 0

for i in range(n):
    j = i + 1
    if a[j][1] == 'BTC':
        ans += a[j][0]*380000
    else :
        ans += a[j][0]
print(ans)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull; 
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define SQ(a) (a)*(a)

template <class T, class U> ostream& operator<< (ostream &out, pair<T,U> c) { out << "(" << c.first << " "; out << c.second << ")"; return out; }
template <class T> ostream& operator<< (ostream &out, vector<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
template <class T> ostream& operator<< (ostream &out, set<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
const double PI  = 3.141592653589793238463;


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int x, a, b, c, r = 0;
    cin  >> a >> b >> c >> x;
    FOR(i,0,a+1){
        FOR(j,0,b+1){
            FOR(k,0,c+1){
                if((i*500 + j*100 + k*50) == x){
                    r++;
                }
            }
        }
    }
    cout << r << endl;  
}

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

using namespace std;

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

long long j[65000];

int main() {
  while (true) {
    long long n, sum = 0, p, ans;
    cin >> n;
    if (n == 0) break;
    rep (i, n) {
      cin >> p;
      sum += p;
    }
    rep (i, n - 1) cin >> j[i];
    sort(j, j + n, greater<int>());
    ans = sum * n;
    rep (i, n - 1) {
      sum += j[i];
      ans = max(ans, sum * (n - i - 1));
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1684
from itertools import*
from math import*
d,g=map(int,input().split())
g//=100
xxx=[tuple([i])+tuple(map(int,input().split()))for i in range(1,d+1)]   #問題数 ボーナス
#print(xxx)
yyy=[(score,score*num+bonus//100,num)for score,num,bonus in xxx]
ans=[]
l=[]
for i in range(d+1):
    for j in combinations(yyy,i):
        tmp1=0
        tmp2=0
        tmpl=set()
        for x,y,z in j:
            tmp1+=y
            tmp2+=z
            tmpl.add(x)
        if tmp1>=g:
            ans.append(tmp2)
        else:
            l.append((tmpl,g-tmp1,tmp2))  
#print(ans)
#print(l)
for s,t,r in l:  #使ったもの 必要なスコア そこまでの枚数
    for x,y,_ in xxx[::-1]:  #スコア 枚数
        if x not in s:
            if x*y<=t:
                break
            else:
#                print(r,t,x)
                ans.append(r+ceil(t/x))

print(min(ans))

Measured memory_bytes: 3572
(function utils(undefined){
	this.print_float = function print_float(val, base, pad, prec) {
		var p10=Math.pow(10,prec);
		var ival=""+Math.round(val*p10);
		if ( ival === '0' )
			return '0.'+Array(prec+1).join('0');
		var ilen=ival.length-prec;
		if(ilen===0)
			return "0."+ival.substr(ilen,prec);
		return ival.substr(0,ilen)+"."+ival.substr(ilen,prec);
	};
}).call(global);

(function math(undefined) {
	this.gcd = function gcd( a, b ) {
		return !b ? a : gcd( b, a % b );
	};
	this.lcm = function lcm( a, b ) {
		return a / gcd( a, b ) * b;
	};
	this.sq = function sq(x) {
		return x * x;
	};
}).call(global);

(function(undefined){
	'use strict';

	(function init() {
		this.output = function() {
			console.log.apply( console, arguments );
		};
		this.stdin = process.openStdin();
		stdin.setEncoding('utf8');
		this.input_list = [];
		stdin.on('data', function(chunk){
			var result = chunk.match(/[-]?\d+/g);
			input_list = input_list.concat(result);
		});
		stdin.on('end', function(){
			fire();
		});
		this.input_number = function() {
			return parseInt( input_list.splice(0,1)[0] );
		};
		this.has_next = function() {
			return ! input_list.length;
		};
	}).call( this );

	(function solver(){
		this.fire = function() {
			setTimeout( solve, 0, this );
		};
		function solve() {
			var args = [input_number(), input_number()];
			output( gcd.apply( this, args ), lcm.apply( this, args ) );
			if ( ! has_next() )
				setTimeout( solve, 0, this );
		}
	}).call(this);

}).call(global);

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

long long int ans = 0;

long long int fun(string s, long long int i)
{
    long long int size = s.size();
    if(i == size - 1){
        long long int bans = 0;
        for(long long int j = 0;j < size;j++){
            if(s[j] == '+'){
                ans += bans;
                bans = 0;
            }
            else{
                bans *= 10;
                bans += s[j] - '0';
            }
        }

        ans += bans;
    }
    else{
        i++;
        fun(s, i);
        s.insert(s.begin() + i, '+');
        fun(s, i + 1);
    }

    return 0;
}

int main()
{
    string s;
    cin >> s;

    fun(s, 0);

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
from math import factorial
n, m = map(int,input().split())
if abs(n-m) >=2:
    print(0)
elif abs(n-m) == 1:
    print((factorial(n)*factorial(m)) % (int(1e9)+7))
else:
    print((factorial(n)*factorial(m)*2) % (int(1e9)+7))

Measured memory_bytes: 5196
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
using Graph = vector<vector<int>>;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){}
};
void dfs(vector<vector<Edge>> &G, vector<bool> &visit, vector<bool> &WB, int v, ll w){
    visit.at(v)=true;

    for(Edge i:G.at(v)){
        if(visit.at(i.to)) continue;
            
        if((w+i.weight)%2) WB.at(i.to)=true;
        else WB.at(i.to)=false;
        dfs(G,visit,WB,i.to,w+i.weight);
    }
}
int main(){
    int N;
    cin>>N;
    vector<vector<Edge>> G(N);
    vector<bool> WB(N,false);
    vector<bool> visit(N,false);
    rep(i,N-1){
        int u,v,w;
        cin>>u>>v>>w;
        u--;
        v--;
        G.at(u).push_back(Edge(v,w));
        G.at(v).push_back(Edge(u,w));
    }
    dfs(G,visit,WB,0,0);
    rep(i,N){
        cout<<WB.at(i)<<endl;
    }
}


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

using namespace std;

typedef long long ll;
#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const ll LINF = 1e18 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

ll f(ll b, ll n) {
  if (n < b) {
    return n;
  } else {
    return f(b, floor(n / b)) + n % b;
  }
}

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

  LCIN(N, S);

  if (N == S) {
    cout << N + 1 << endl;
    return 0;
  }

  // b ≦ √n(bが小さい時)
  FOR(bi, 2, sqrt(N) + 1ll) {
    if (f(bi, N) == S) {
      cout << bi << endl;
      return 0;
    }
  }

  ll ans = LINF;
  // b > √n(bが大きい時)
  FOR(pi, 1, sqrt(N - S) + 1ll) {

    // piが約数でない時は適していない
    if (abs(N - S) % pi != 0) {
      continue;
    }

    // n - s = p(b - 1)より、
    // b = (n - s) / pi + 1として表せる
    ll b = (N - S) / pi + 1;

    // 条件(b > √n)を満たしていない時は適していない
    if (b <= sqrt(N)) {
      continue;
    }
    // 解は最小値である
    if (f(b, N) == S) {
      ans = min(ans, b);
    }
  }

  
  if (ans < LINF) {
    cout << ans << endl;
  } else {
    // 最小値が更新されていない時は解なし
    cout << -1 << endl;
  }
  
  return 0;
}



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

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

    ll start = 100;
    ll cnt = 0;
    while(start < x){
        start += (start/100);
        cnt++;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

int main() {
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if((x>=r && x+r<=W) && (y>=r && y+r<=H) )
		 {	 printf("Yes\n");
	} else { printf("No\n");}
}



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

using namespace std;using f64 = double;using i64=long long;using u64=unsigned long long;
template<typename T> using Arr=vector<T>;
#define hfor(v, s, e) for(int v=(s);(s)<=v&&v<(e);++v)//half-opened range
#define hfori(v, s, e) for(int v=(e)-1;(s)<=v&&v<(e);--v)//inversion
#define hforo(v, s, e) int v=(s);for(;(s)<=v&&v<(e);++v)//out declaration
#define hforoi(v, s, e) int v=(e)-1; for(;(s)<=v&&v<(e);--v)
#define cfor(v, s, e) hfor(v,(s),(e)+1)//closed range
#define cfori(v, s, e) hfori(v,(s),(e)+1)
#define cforo(v, s, e) hforo(v,(s),(e)+1)
#define cforoi(v, s, e) hforoi(v,(s),(e)+1)
#define rep(v,x) hfor(v,0,(x))
#define repi(v,x) hfori(v,0,(x))
#define repo(v,x) hforo(v,0,(x))
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pushb push_back
#define pushf push_front
#define popb pop_back
#define popf pop_front
#define empl emplace
#define emplb emplace_back
#define emplf emplace_front
#define fi first
#define se second
#define cxp constexpr
#define PQ std::priority_queue

#ifndef DEBUG
	#pragma GCC optimize ("Ofast")
	auto __PRE_RUN__=(ios::sync_with_stdio(0), cin.tie(0), cout.tie(0),(cout<<fixed<<setprecision(11)), 0);
#endif

template<typename T> cxp T inf() { return numeric_limits<T>::max() / 2; }
auto mapf(auto a, auto f){for(auto& x:a)x=f(x); return a;}
int rd(int lb, int ub){static mt19937 rng(time(0)^i64(new int)); return uniform_int_distribution<int>(lb, ub-1)(rng);}
int rd(int ub=inf<int>()){return rd(0,ub);}
const f64 pi=acosl(-1);
#define endl '\n'//not interactive?
#define int i64//MLE?
using pint = pair<int,int>;
using tint = tuple<int,int,int>;

signed main(){
	int n; cin>>n;
	Arr<int> a(n), b(n), c(n);
	rep(i,n)
		cin>>a[i];
	rep(i,n)
		cin>>b[i];
	c=a;
	sort(all(c));
	int i=0, ai, bi;
	do{
		if(c==a)
			ai=i;
		if(c==b)
			bi=i;
		i++;
	}while(next_permutation(all(c)));
	cout<<abs(ai-bi)<<endl;

	return 0;
}



Measured memory_bytes: 256
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import           Control.Monad.ST            (ST, runST)
import           Data.Bits                   (shiftL, shiftR, testBit, (.&.))
import qualified Data.ByteString.Char8       as BC
import           Data.Maybe                  (fromJust)
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM


main :: IO ()
main = do
  n <- readLn
  as <- getInts
  bs <- getInts
  print $ solve n as bs

solve :: Int -> [Int] -> [Int] -> Int
solve n as bs = sum $ map kXorBit [0 .. 28] where
  bv = V.fromList bs
  kXorBit k = if odd s then t else 0 where
    t = 1 `shiftL` k
    t2 = 1 `shiftL` (k + 1)
    cs = sort' $ V.map modT2 bv
    s = sum $ map count as
    mask = t2 - 1
    modT2 = (mask .&.)
    count a = (t12 - t01) + (n - t23) where
      t01 = binarySearch cs $ t - a'
      t12 = binarySearch cs $ t2 - a'
      t23 = binarySearch cs $ 3 * t - a'
      a' = modT2 a

binarySearch :: V.Vector Int -> Int -> Int
binarySearch xs y = go 0 $ V.length xs where
  go l r
    | l == r = l
    | x < y = go (m + 1) r
    | x >= y = go l m
    where m = (r + l) `shiftR` 1
          x = xs `V.unsafeIndex` m

odd' :: Int -> Bool
odd' n = testBit n 0

readInts :: BC.ByteString -> [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words

getInts :: IO [Int]
getInts = readInts <$> BC.getLine

sort' :: V.Vector Int -> V.Vector Int
sort' xs = runST $ do
  v <- V.thaw $ xs
  quicksort v 0 $ VM.length v
  V.freeze v

-- https://github.com/as-capabl/haskell-qsort-pfm/blob/master/src/UV.hs
type IndType = Int

quicksort :: VM.STVector s Int -> IndType -> IndType -> ST s ()
quicksort work iStart iEnd
    | iEnd - iStart <= 1 = return ()
    | otherwise =
      do
        pivot <- VM.unsafeRead work ((iEnd + iStart) `shiftR` 1)
        med <- divide pivot iStart (iEnd - 1)
        quicksort work iStart med
        quicksort work med iEnd
  where
    divide pivot iS' iE'
        | iS' > iE' = return iS'
        | otherwise =
          do
            lower <- shrinkLower pivot iS' iE'
            higher <- shrinkHigher pivot lower iE'
            if lower >= higher
              then do
                return lower
              else do
                swapWork lower higher
                divide pivot (lower + 1) (higher - 1)

    shrinkLower pivot iS' iE'
        | iS' > iE' = return iS'
        | otherwise =
          do
            x <- VM.unsafeRead work iS'
            if x >= pivot
              then
                return iS'
              else
                shrinkLower pivot (iS' + 1) iE'

    shrinkHigher pivot iS' iE'
        | iS' > iE' = return iE'
        | otherwise =
          do
            x <- VM.unsafeRead work iE'
            if x <= pivot
              then
                return iE'
              else
                shrinkHigher pivot iS' (iE' - 1)

    swapWork i j = VM.unsafeSwap work i j


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

#define MAX 100000
typedef long long llong;

int n,k;
llong T[MAX];

int check(int P){
    int j=0;
    for(int i=0;i<k;i++){
        llong sum=0;
        while(sum+T[j]<=P){
            sum += T[j];
            j++;
            if(j==n)return n;
        }
    }
    return j;
}

int main(){
    cin >> n >> k;
    for(int i=0;i<n;i++) cin >> T[i];

    llong left=0,right=100000*10000,mid;
    while(right-left>1){
        mid = (left+right)/2;
        if(check(mid)>=n)right=mid;
        else left=mid;
    }
    cout << right << endl;

    return 0;
}



Measured memory_bytes: 3872
#include <iostream>
#include <vector>

int main()
{
	int n = 0;
	std::vector<int> X;

	std::cin >> n;
	for (int i = 0; i < n; ++i) {
		int x = 0;
		std::cin >> x;
		X.push_back(x);
	}
    float avg = 0.0f;
    for (int i = 0; i < n; ++i) {
        avg += X[i];
    }
    avg /= (float)n;
    int nAvg = (int)(avg + 0.5f);

    int minsum = 0;
    for (int i = 0; i < n; ++i) {
        minsum += (X[i] - nAvg) * (X[i] - nAvg);
    }

    std::cout << minsum;


    return 0;
}

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

int main () {
  int N,P;
  cin >> N >> P;
  vector<int>A(N);
  int count = 0;
  long long sum = 1;
  
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    sum *= 2;
    if (A.at(i) % 2 == 1){
      count = 1;
    }
  }
  
  if (count == 1){
    cout << sum/2 << endl;
  }
  else {
    if (P == 0){
      cout << sum << endl;
    }
    else {
      cout << 0 << endl;
    }
  }
}
  
  

Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
int main(void){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(b/a > c){
		printf("%d",c);
	}else{
		printf("%d",b/a);
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int num1, num2, num3, temp;
    cin >> num1 >> num2 >> num3;
    for(int i = 0; i < 2; ++i){
        if(num1 > num2){
            temp = num1;
            num1 = num2;
            num2 = temp;
        }
        if(num2 > num3){
            temp = num2;
            num2 = num3;
            num3 = temp;
        }
    }
    cout << num1 << " " << num2 << " " << num3 << endl;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
int a[4][14];
int main()
{
  int n, b;
  char c;
  char s[] = "SHCD";
  std::cin >> n;
  for (int i = 0; i < n; i++)
  {
    std::cin >> c >> b;
    if (c == 'S')
      a[0][b]++;
    else if (c == 'H')
      a[1][b]++;
    else if (c == 'C')
      a[2][b]++;
    else
      a[3][b]++;
  }
  for (int i = 0; i < 4; i++)
  {
    for (int j = 1; j <= 13; j++)
    {
      if (!a[i][j])
      {
        std::cout << s[i] << " " << j << std::endl;
      }
    }
  }
}



Measured memory_bytes: 3076
#include <stdio.h>
#include <string.h>
int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a>b?a:b;}
int main(void){
    char s[100020];
    scanf("%s",s);
    int ans=strlen(s);
    for (int i=1; i<strlen(s); i++){
        if (s[i]==s[i-1]){
        } else {
            ans=min(ans,max(i,strlen(s)-i));
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
def main(year, month):
    if (month == 0 or month > 12) and (year == 0 or year > 12):
        print("NA")
        return
    if month == 0 or month > 12:
        print("MMYY")
        return
    if year == 0 or year > 12:
        print("YYMM")
        return
    print("AMBIGUOUS")


input_str = input()
year, month = int(input_str[:2]), int(input_str[2:])

main(year, month)

Measured memory_bytes: 3060
#include<stdio.h>

int main(void){
    int n, m, x, y, x1, x2=-100, y1, y2=100;
    scanf("%d%d%d%d", &n, &m, &x, &y);
    for(int i=0; i<n; i++){
        scanf("%d", &x1);
        if(x1>x2) x2=x1;
    }
    if(x2<x) x2=x;
    for(int i=0; i<m; i++){
        scanf("%d", &y1);
        if(y1<y2) y2=y1;
    }
    if(y2>y) y2=y;
    if(x2<y2) printf("No War\n");
    else printf("War\n");
}

Measured memory_bytes: 128
#include<stdio.h>

int main()
{
   int a,b,c;
   scanf("%d%d%d",&a,&b,&c);
   if((a == 5|| a == 7) && (b == 5 || b == 7) && (c == 5 || c ==7) && a+b+c == 17)
   {
   	printf("YES");
   }
   else
   {
    printf("NO");  
   }
   return 0;
}

Measured memory_bytes: 128
n = int(input())
h_kari =list(map(int, input().split()))
h = []

for i in range(n):
    h.append([h_kari[i],i+1])
    
h.sort()    
    
ans = [h[i][1] for i in range(n)]    

print(' '.join(map(str, ans)))
    

Measured memory_bytes: 28416
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

int main(void)
{
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];
  REP(i,n) REP(j,i) {
    if ((a[j]-a[i])%(n-1)) continue;
    cout << a[j] << ' ' << a[i] << endl;
    return 0;
  }
  return 0;
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int N,K,num=1;
      cin >> N >> K;
      for(int i=0; i<N ; i++){
        if(2*num < num+K)num *= 2;
        else num += K;
      }
      cout << num;
    }

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>

#include<queue>
#include <iomanip>
#include<set>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF 1844674407370955161
typedef long long int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007


int main()
{
    string S;
    cin>>S;
    int N=S.size();
    bool flag=true;
    REP(i,0,N){
        if(i%2==0){
            if(S[i]=='L'){
                flag=false;
            }
        }else{
            if(S[i]=='R'){
                flag=false;
            }
        }
    }
    if(flag){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

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

class E
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var map = new List<int>[1001000];
		for (var i = 1; i <= n; i++)
			for (var j = i + 1; j <= n; j++)
				map[1000 * j + i] = new List<int>();
		for (var i = 1; i <= n; i++)
		{
			var a = Console.ReadLine().Split().Select(int.Parse).Select(j => i > j ? 1000 * i + j : 1000 * j + i).ToArray();
			var m = n - 2;
			for (int j = 0, k = 1; j < m; j++, k++) map[a[j]].Add(a[k]);
		}

		var cs = new int[1001000];
		var rs = new bool[1001000];
		for (var id = 0; id < map.Length; id++) if (map[id] != null) Find(map, id, cs, rs);
		Console.WriteLine(cs.Max());
	}

	static void Find(List<int>[] map, int id, int[] cs, bool[] rs)
	{
		if (cs[id] > 0) return;
		if (map[id].Count == 0) { cs[id] = 1; return; }
		if (rs[id]) { Console.WriteLine(-1); Environment.Exit(0); }
		rs[id] = true;
		foreach (var pid in map[id]) Find(map, pid, cs, rs);
		cs[id] = map[id].Max(i => cs[i]) + 1;
		rs[id] = false;
	}
}


Measured memory_bytes: 93832
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define     FAST        ios_base::sync_with_stdio(false);cin.tie(NULL)
#define     int 	    long long
#define 	pb 	        push_back
#define 	mp 	        make_pair
#define 	pi 	        2*acos(0.0)
#define     scan(i)     scanf("%lld",&i)
#define     scann(i,j)  scanf("%lld%lld",&i,&j)
#define     print(i)    printf("%lld\n",i)
#define     printt(i,j) printf("%lld %lld\n",i,j)
#define     loop(i,n) 	for(int i = 1 ; i <=n ; i++)
#define 	vect 	    vector<int>
#define 	vec_it 	    vector<int>::iterator vi
#define     sorta(v)    sort(v.begin(),v.end())
#define     sortd(v)    sort(v.begin(),v.end(),greater<>())
#define 	mapp 	    map<int,int>
#define 	pairr 	    pair<int,int>
#define 	sett	    set<int>
#define 	set_it 	    set<int>::iterator si
#define     map_it      map<int,int> :: iterator mi
#define 	yes 	    cout<<"Yes"<<endl
#define 	no 	        cout<<"No"<<endl
#define 	ff 	        first
#define 	ss 	        second
#define     mx          INT_MAX
#define     lmx         LLONG_MAX
#define     mn          INT_MIN
#define     lmn         LLONG_MIN
#define     GCD         __gcd(a,b)
#define     LCM         (a/GCD)*b
template <typename T> T gcd(T a,T b){return (b==0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {return a*(b/gcd(a,b));}
int modulo (int a, int b) { return a >= 0 ? a % b : ( b - abs ( a%b ) ) % b; }

void solve()
{
  //  freopen ("(input).txt" , "r",  stdin) ;
  //  string st,stt ;
  //  int low=0,high=0;
  //  int l,r;
  //  FAST;
    int n,k,t,b,c,x,y,z,d=0,temp=0,cnt=0,sum=0,f=0;
    cin>>n  ; vect v ,a  ; sett s ; set_it ; mapp m ; pairr p; map_it;
    loop(i,100)
    loop(j,100)
    loop(kk,100)
    {
        temp=i*i+j*j+kk*kk+i*j+j*kk+kk*i;
        m[temp]++;
    }
    loop(i,n)
    {
        cout<<m[i]<<endl;
    }

}

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


Measured memory_bytes: 6032
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
#include<cmath>
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back

using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const int MAX_H=101;

ll calc(ll H,ll W){
  ll res=INF;
  ll a,b,c;
  ll temp=(H+2)/3;
  a=temp*W;
  b=(H-temp)*(W+1)/2;
  c=(H-temp)*floor(W/2);
  //cout << a << ","<< b << "," << c << endl;
  res=min(res,max(max(a,b),c)-min(min(a,b),c));
  //cout << res << endl;

  b=floor((H-temp)/2)*W;
  c=((H-temp+1)/2)*W;
  res=min(res,max(max(a,b),c)-min(min(a,b),c));
  //cout << res << endl;

  a=H/3*W;
  b=(H-H/3)*((W+1)/2);
  c=(H-H/3)*floor(W/2);
  //cout << a << ","<< b << "," << c << endl;
  res=min(res,max(max(a,b),c)-min(min(a,b),c));
  //cout << res << endl;

  b=floor((H-H/3)/2)*W;
  c=((H-H/3+1)/2)*W;
  res=min(res,max(max(a,b),c)-min(min(a,b),c));
  //cout << res << endl;

  return res;
}

int main(){
  ll H,W;
  cin >> H >> W ;
  ll ans=min(calc(H,W),calc(W,H));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[103],b[103],h[103],x=-1;
int main(){
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i]>>b[i]>>h[i];
		if(h[i]!=0)x=i;
	}
	if(x==-1){
		cout<<"37 15 1";
		return 0;
	}
	for(int i=0;i<=100;i++)
		for(int j=0;j<=100;j++)
		{
			bool can=1;
			for(int k=0;k<n;k++)
				if(k!=x)
					if(fabs(a[k]-i)+fabs(b[k]-j)+h[k]!=fabs(a[x]-i)+fabs(b[x]-j)+h[x]&&(h[k]!=0||fabs(a[x]-i)+fabs(b[x]-j)+h[x]>=fabs(a[k]-i)+fabs(b[k]-j)))
						can=0;
			if(can){
				cout<<i<<' '<<j<<' '<<int(h[x]+fabs(a[x]-i)+fabs(b[x]-j))<<endl;
				return 0;
			}
		}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define mp make_pair
inline double sq(double a) { return a*a; }

int n, ox[200], oy[200];

int main() {
    for(;;) {
        scanf("%d", &n);
        if(n==0) return 0;
        rep(i, n) scanf("%d%d", ox+i, oy+i);
        vector<int> ys;
        rep(i, n) ys.push_back(oy[i]);
        sort(ys.begin(), ys.end());
        ys.erase(unique(ys.begin(), ys.end()), ys.end());
        vector<double> x;
        vector<int> y;
        rep(i, n) {
            x.push_back(ox[i]);
            y.push_back(oy[i]);
            if(i==n-1) break;
            if(oy[i]<oy[i+1]) {
                rep(j, ys.size()) if(oy[i]<ys[j] && ys[j]<oy[i+1]) {
                    const double dx = ox[i+1]-ox[i], dy = oy[i+1]-oy[i];
                    x.push_back(ox[i]+dx/dy*(ys[j]-oy[i]));
                    y.push_back(ys[j]);
                }
            }
            else if(oy[i]>oy[i+1]) {
                const int m = ys.size();
                for(int j=m-1; j>=0; j--) if(oy[i+1]<ys[j] && ys[j]<oy[i]) {
                    const double dx = ox[i+1]-ox[i], dy = oy[i+1]-oy[i];
                    x.push_back(ox[i]+dx/dy*(ys[j]-oy[i]));
                    y.push_back(ys[j]);
                }
            }
        }
        typedef pair<int, int> node;
        set<node> vis;
        priority_queue<pair<double, node> > q;
        q.push(mp(0, mp(0, x.size()-1)));
        while(!q.empty()) {
            pair<double, node> vv(q.top());
            q.pop();
            const double c = -vv.first;
            const int l = vv.second.first;
            const int r = vv.second.second;
            if(vis.find(mp(l, r))!=vis.end()) continue;
            vis.insert(mp(l, r));
            if(l==r) {
                printf("%.9f\n", c);
                break;
            }
            for(int i=-1; i<=1; i++) if(0<=l+i && l+i<(int)x.size()) {
                for(int j=-1; j<=1; j++) if(0<=r+j && r+j<(int)x.size()) {
                    if(y[l+i]==y[r+j]) {
                        const double d1 = sqrt(sq(x[l]-x[l+i])+sq(y[l]-y[l+i]));
                        const double d2 = sqrt(sq(x[r]-x[r+j])+sq(y[r]-y[r+j]));
                        q.push(mp(-c-d1-d2, mp(l+i, r+j)));
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 2080
import java.util.*;
class Main {
    public static void main (String[] args) throws java.lang.Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        for(int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if('a' <= c && c <= 'z') System.out.print((char)(c - 32));
            else if('A' <= c && c <= 'Z') System.out.print((char)(c + 32));
            else System.out.print(c);
        }
        System.out.println();
    }
}



Measured memory_bytes: 26996
S = list(input())
i = 0
import copy
original_S = copy.copy(S)



S = copy.copy(original_S)
i = 0
if S[i] != "A":
    S = ["A"] + S
    i += 1
while True:
    if i >= len(S):
        break
    if S[i] == "H" or S[i] == "B" or S[i] == "R":
        if i == len(S) - 1:
            S = S[:i + 1] + ["A"] + S[i + 1:]
            i += 1
        elif S[i + 1] != "A":
            S = S[:i + 1] + ["A"] + S[i + 1:]
            i += 1
    i += 1
    
if S == ["A", "K", "I", "H", "A", "B", "A", "R", "A"]:
    print("YES")
else:
    print("NO")
        

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> a(H);
  for (int i = 0; i < H; i++)
  {
    cin >> a[i];
  }
  vector<bool> rows(H, false);
  vector<bool> cols(W, false);
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      if (a[i][j]=='#')
      {
        rows[i] = true;
        cols[j] = true;
      }
    }
  }
  for (int i = 0; i<H; i++) {
    if (rows[i]) {
      for (int j = 0; j < W; j++)
      {
        if (cols[j]) {
          cout << a[i][j];
        }
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int Max = 1000000;
int main(){
  	int N, M;
  	cin >> N >> M;

  	cout << (N*(N-1) + M*(M-1) )/2<<endl;

    
  	return 0;
}



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

class B
{
	static void Main()
	{
		var h = Console.ReadLine().Split().Select(int.Parse).ToArray();
		var a = new int[h[0]].Select(_ => new HashSet<int>(Console.ReadLine().Split().Select(int.Parse).Skip(1))).ToArray();
		Console.WriteLine(Enumerable.Range(1, h[1]).Count(i => a.All(s => s.Contains(i))));
	}
}


Measured memory_bytes: 13652
#include <stdio.h>
int main(void)
{
    int a,b,c;
    int tmp;    
    scanf("%d%d%d", &a,&b,&c);
    
    if(a > b){
       tmp = a;
       a = b;
       b = tmp;
    }
    if (b > c){
       tmp = b;
       b = c;
       c = tmp;
    }
    if (a > b){
       tmp = a;
       a = b;
       b = tmp;
    }
    printf("%d %d %d\n", a,b,c);
    return 0;
}

Measured memory_bytes: 1024
N, M = gets.chop.split.map(&:to_i)
a = Array.new(M)
b = Array.new(M)
M.times{|i|
  a[i], b[i] = gets.chop.split.map(&:to_i)
  a[i] -= 1
  b[i] -= 1
}

# 隣接リスト
$adj = Array.new(N){Array.new()}
M.times{|i|
  $adj[a[i]].push(b[i])
  $adj[b[i]].push(a[i])
}
$cnt = 0
$vis = Array.new(N){true}
$vis[0] = false
def dfs(i, v)
  if i == N - 1
    $cnt += 1
  else
    $adj[v].each do |u|
      if $vis[u]
        $vis[u] = false
        dfs(i + 1, u)
        $vis[u] = true
      end
    end
  end
end

dfs(0, 0)
puts $cnt

Measured memory_bytes: 3836