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

using namespace std;

const int maxn = 25;
const int INF = 0x7f7f7f7f;

int a[maxn][maxn] , c[maxn];
int ans[maxn];

int main() {
	int n , m , x;
	int res = INF;
	ios::sync_with_stdio(0);
	cin >> n >> m >> x;
	for(int i = 0 ; i < n ; i++) {
		cin >> c[i];
		for(int j = 0 ; j < m ; j++) {
			cin >> a[i][j];
		}
	}
	for(int i = (1 << n) - 1 ; i >= 0 ; i--) {
		int t = i , cnt = 0;
		bool flag = 0;
		memset(ans , 0 , sizeof(ans));
		for(int j = 0 ; j < n ; j++) {
			if(t % 2) {
				for(int k = 0 ; k < m ; k++) {
					ans[k] += a[j][k];
				}
				cnt += c[j];
			}
			t /= 2;
		}
		
		for(int i = 0 ; i < m ; i++) {
			if(ans[i] < x) {
				flag = 1;
				break;
			}
		}
		if(!flag) {
			res = min(res , cnt);
		}
	}
	if(res != INF) {
		cout << res << "\n";
	}
	else cout << -1 << "\n"; 
	return 0;
}

Measured memory_bytes: 3656
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
typedef pair<int,int> pii;
#define fi first
#define se second
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/4
#define INTINF INT_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T &a, T b){if(a < b){a = b;return true;}return false;}
template<class T> inline bool chmin(T &a, T b){if(a > b){a = b;return true;}return false;}
/*----------------------------------------------------------------*/
// const int MOD = 998244353;
const int MOD = 1000000007;

/*----------------------------------------------------------------*/
signed main(){

	
	int n,m,k;
	cin >> n >> m >> k;

	for(int i = 0;i <= n;i++){
		for(int j = 0;j <= m;j++){
			if(i*j + (n-i)*(m-j) == k){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;


	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=gnu++17 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2017-qualb.contest.atcoder.jp/tasks/code_festival_2017_qualb_b
// rm -r -f test;oj dl https://code-festival-2017-quala.contest.atcoder.jp/tasks/code_festival_2017_quala_b


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

int main()
{
	int a,b;
	while(cin>>a>>b){
		if(a>=13)cout<<b<<endl;
		else if(a>=6&&a<=12)cout<<b/2<<endl;
		else cout<<0<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
l = [-1 for i in range(N)]
for i in range(N):
  A = int(input())
  ok = N-1
  ng = -1
  while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    if l[mid] < A:
      ok = mid
    else:
      ng = mid  
  l[ok] = A
###
for i in range(N):
  if l[i] == -1:
    ans = i
    break
  #出会わなかったパターンを忘れ気味
  if i == N-1:
    ans = N  
print(ans)    

Measured memory_bytes: 48368
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static readonly int INF = int.MaxValue / 2;

        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            int n = int.Parse(Console.ReadLine());

            int[,] map = new int[n + 1, n + 1];

            for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j <= n; j++)
                {
                    map[i, j] = INF;
                }
            }

            for (int i = 0; i < n; i++)
            {
                int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

                int id = input[0];
                int len = input[1];

                for (int j = 0; j < len; j++)
                {
                    map[id, input[2 + j]] = 1;
                }
            }

            for (int k = 1; k <= n; k++)
            {
                for (int i = 1; i <= n; i++)
                {
                    for (int j = 1; j <= n; j++)
                    {
                        map[i, j] = Math.Min(map[i, j], map[i, k] + map[k, j]);
                    }
                }
            }

            int p = int.Parse(Console.ReadLine());

            while (p-- > 0)
            {
                int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

                int from = input[0];
                int to = input[1];
                int maxV = input[2];

                int v = map[from, to] + 1;

                if (v > maxV) sb.AppendLine("NA");
                else sb.AppendLine(v.ToString());
            }
            Console.Write(sb);
        }
    }
}

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

using namespace std;

#ifndef ONLINE_JUDGE
  #define pr_debug(...) do { printf("DEBUG: line %d: %s: ", __LINE__, __PRETTY_FUNCTION__); printf(__VA_ARGS__); } while(0)
  #define pr_vars(...) do { pr_debug(" "); pr_var(split(#__VA_ARGS__, ',').begin(), __VA_ARGS__); } while(0)
#else
  __attribute__ ((constructor)) static void fast_cin() { ios_base::sync_with_stdio(false); cin.tie(0); }
  #define pr_debug(...) do { } while(0)
  #define pr_vars(...) do { } while(0)
#endif /* ONLINE_JUDGE */

using ll = int64_t;
using ull = uint64_t;

template<typename X, typename Y> ostream &operator<< (ostream &fout, const pair<X, Y> &p)
{ fout << '{' << p.first << ", " << p.second << "} "; return fout; }

template<typename T> ostream &operator<< (ostream &fout, const vector<T> &vec)
{ for (const auto &el : vec) fout << el << ' '; return fout; }

template<typename T> istream &operator>> (istream &fin, vector<T> &vec)
{ for (size_t i = 0; i < vec.size(); i++) fin >> vec[i]; return fin; }

vector<string> split(const string &s, char c) { vector<string> v; ull st = 0, fn = 0, lvl = 0;
for ( ; fn < s.size(); fn++ ) { if (s[fn] == c && lvl == 0) { v.push_back(s.substr(st, fn - st)); st = fn + 1; }
if (s[fn] == '(') { lvl++; } if (s[fn] == ')') { lvl--; } } v.push_back(s.substr(st, fn - st)); return v; }

void pr_var(vector<string>::iterator it) { (void) it; cout << endl; }
template<typename T, typename... Args> void pr_var(vector<string>::iterator it, T a, Args... args)
{ cout << *it << "=" << a << "  "; pr_var(++it, args...); }

ll div_ceil(ll n, ll d) { ll res = n / d; if (res >= 0) res += n % d ? 1 : 0; return res; }
ll gcd(ll a, ll b) { a = llabs(a); b = llabs(b); while (a && b) a > b ? a %= b : b %= a; return a + b; }
ll lcm(ll a, ll b) { ll c = gcd(a, b); return c == 0 ? 0 : llabs(a / c * b); }

#define setp(a) fixed << setprecision(a)
const double PI = acos(-1.0);
constexpr double EPS = 1e-9;
constexpr double INF = 2e18;

using mp = pair<ll, ll>;
using mt = tuple<ll, ll, ll>;    // unpack: tie(ll, ll, ll) = mt;

constexpr ll MAX = 1e3 + 5;

int main()
{    
    map<ll, mp> m;

    ll h, w, d; cin >> h >> w >> d;
    for (ll i = 0; i < h; i++) {
        for (ll j = 0; j < w; j++) {
            ll a; cin >> a;
            m[a] = mp(i, j);
        }
    }

    vector<vector<ll>> p(d + 1);
    for (ll i = 1; i <= d; i++) {
        p[i].push_back(0);
        ll cur = 0;
        for (ll j = i + d; j <= h * w; j += d) {
            mp st = m[j - d];
            mp fn = m[j];
            cur += llabs(st.first - fn.first) + llabs(st.second - fn.second);
            p[i].push_back(cur);
        }
        //pr_vars(i, p[i]);
    }

    ll q; cin >> q;
    while (q--) {
        ll res = 0;
        ll l, r; cin >> l >> r;
        //if (l == r) { cout << 0 << "\n"; continue; }

        ll idx = l % d, li = div_ceil(l, d) - 1, ri = div_ceil(r, d) - 1;
        if (idx == 0) idx = d;
        //pr_vars(idx, li, ri);
        res = p[idx].at(ri) - p[idx].at(li);

        cout << res << "\n";
    }

    return 0;
}


Measured memory_bytes: 11008
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

int main() {
    ll N;
    cin >> N;
    vector<ll> ais;
    ll max_abs_idx = -1;
    ll max_abs = numeric_limits<ll>::min();
    bool is_pos = false;
    for (ll i = 0; i < N; i++) {
        ll ai;
        cin >> ai;
        ais.push_back(ai);
        if (abs(ai) > max_abs) {
            max_abs_idx = i;
            max_abs = abs(ai);
            is_pos = (ai > 0);
        }
    }
    cout << 2 * N - 2 << endl;
    for (ll i = 0; i < N; i++) {
        if (i == max_abs_idx) {
            continue;
        }
        cout << (max_abs_idx+1) << " " << (i+1) << endl;
    }
    for (ll i = 0; i < N-1; i++) {
        ll x, y;
        if (is_pos) {
            x = i;
            y = x+1;
        } else {
            x = N-1-i;
            y = x-1;
        }
        cout << (x+1) << " " << (y+1) << endl;
    }
}



Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int a=s.length();
    int maxn=0,res=0;
    for(int i=0;i<=a;i++)
    {
        for(int j=i;j<=a;j++)
        {
            if(s[j]=='A'||s[j]=='C'||s[j]=='G'||s[j]=='T')
            {
                res++;
            }
            else
            {
                if(res>maxn)
                    maxn=res;
                res=0;
                break;
            }
        }
    }
    cout<<maxn<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    char s[3];
    int i,a=0;
    for(i=0;i<3;i++){
        cin>>s[i];}
        if(s[0]=='R' && s[1]=='R' && s[2]=='R')
            cout<<"3"<<endl;
        else if(s[0]=='R' && s[1]=='S' && s[2]=='R')
            cout<<"1"<<endl;
        else if(s[0]=='R' && s[1]=='R' && s[2]=='S')
            cout<<"2"<<endl;
        else if(s[0]=='S' && s[1]=='R' && s[2]=='R')
            cout<<"2"<<endl;
        else if(s[0]=='R' && s[1]=='S' && s[2]=='S')
            cout<<"1"<<endl;
        else if(s[0]=='S' && s[1]=='R' && s[2]=='S')
            cout<<"1"<<endl;
        else if(s[0]=='R' && s[1]=='S' && s[2]=='S')
            cout<<"1"<<endl;
        else if(s[0]=='S' && s[1]=='S' && s[2]=='R')
            cout<<"1"<<endl;
        else
            cout<<"0"<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
int main(){
  int s,h,m;
  int S;
  scanf("%d",&S);
  h=S/(60*60);
  m=(S-h*3600)/60;
  s=(S-h*3600-m*60)%60;
  printf("%d:%d:%d\n",h,m,s);
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
//#include <ext/rope>

#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define last(s) (s)[int((s).size())-1]
#define prelast(s) (s)[int((s).size())-2]
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define elif else if
#define left asdasd
#define next zaza

#define cclear cout<<flush;
#define x0 kerker
#define time chas
#define y0 lolik
#define kchay ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define files freopen("a.in", "r", stdin);freopen("a.out", "w", stdout);
#define ref svyazi
#define int long long
#define ii pair<int, int>
#define ld long double
#define list spisok


using namespace std;
//using namespace __gnu_cxx;

bool cmp(int a,int b){
    return a>b;
}

int n,k,a[1010],sm,ans;
vector<int> all_sm[50];
main(){
    kchay;
    cin >> n >> k;
    for (int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n;i++){
        sm=0;
        for (int j=i;j<n;j++){
            sm+=a[j];
            all_sm[0].pb(sm);
        }
    }
    sort(all(all_sm[0]),cmp);
    int bt=1;
    while (bt<all_sm[0][0]){
        bt*=2;
    }
    bt/=2;
    int z;
    for(z=0;bt>=1;bt/=2){
            if (all_sm[z].size()<k) {
                z--;
                break;
            }
            int l=0;
            for(auto i:all_sm[z]){
                if (i&bt) l++;
                if (l==k) break;
            }
            if (l==k){
                for (auto i:all_sm[z]){
                    if (i&bt){
                        all_sm[z+1].pb(i);
                    }
                }
                z++;
            }
    }
    ans=all_sm[z][0];
    for (int i=0;i<k;i++){
        ans&=all_sm[z][i];
    }
    cout<<ans;
}


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

int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size();
  int ans = 0;
  rep(i, n) {
    if (s[i] != t[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3848
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////

int main(){
    string s,t;cin>>s>>t;
    cout<<t+s<<endl;
    
    return 0;
}



Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
a2 = [a[0]]
for i in range(n-1):
  a2.append(a2[i]+a[i+1])

ans = []

if n == 2:
  print(abs(a[0]-a[1]))
  exit()

for i in range(n-1):
  tmp = abs(a2[-1] - 2*a2[i])
  ans.append(tmp)
print(min(ans))

Measured memory_bytes: 114428
import math
N,D=map(int,input().split())
X=[]
cnt=0
def distance(x,y):
    d2=[]
    for k in range(D):
        d2.append((X[x][k]-X[y][k])**2)
    return math.sqrt(sum(d2))
for i in range(N):
    X.append(list(map(int,input().split())))
for j in range(N-1):
        for l in range(j+1,N,):
            if float.is_integer(distance(j,l)):
                cnt+=1 
print(cnt)


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

int main() {
        int x, n, ans = -1;
        cin >> x >> n;
        vector<int> arr(n);
        for(int i = 0 ; i<n ; i++) {
                cin >> arr[i];
        }
        ans = x;
        if(n > 0){
                int mx = *max_element(arr.begin(), arr.end());
                int mn = *min_element(arr.begin(), arr.end());
                int p[100];
                int count = 0;
                for(int i = mn-1 ; i<=mx+1 ; i++) {
                        if(find(arr.begin(), arr.end(), i) == arr.end()) {
                                p[count++] = i;
                        }
                }
                int d = abs(x - p[0]);
                ans = p[0];
                for(int i = 1 ; i<count ; i++){
                        if(d > abs(x-p[i])){
                                d = abs(x-p[i]);
                                ans = p[i];
                        }
                }
        }
        cout << ans << "\n";
        return 0;
}

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

#define int long long

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

#define endl '\n'

#define pb push_back
#define mp make_pair

#define fi first
#define se second

#define r(a) cin>>a
#define r2(a,b) cin>>a>>b
#define r3(a,b,c) cin>>a>>b>>c
#define r4(a,b,c,d) cin>>a>>b>>c>>d

#define p(a) cout<<a<<' '
#define pn(a) cout<<a<<endl
#define p2n(a,b) cout<<a<<' '<<b<<endl
#define p3n(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl
#define p4n(a,b,c,d) cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl
#define psn cout<<endl

#define repeat(i,n) for(int i=0;i<n;++i)
#define repeat2(i,a,b) for(int i=a;i<b;++i)
#define rfor(i,n) for(int i=n-1;i>=0;--i)
#define range(i,a) for(auto &i:a)

#define readall(t) range(i,t)r(i)
#define printall(t) range(i,t)p(i);psn

#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

#define sz(a) (int)a.size()
#define len(a) (int)a.length()
#define all(a) a.begin(),a.end()

const int MOD = 1000000007;
const int MAXN = 1000;
const int ROCKY = -1;

char grid[MAXN][MAXN];
int dp[MAXN][MAXN];
int h, w;

void init()
{
    repeat(i, MAXN)
        repeat(j, MAXN)
            dp[i][j] = ROCKY;
}

int ans(int x, int y)
{
    if (x == h - 1 && y == w - 1)
        return 1;
    if (grid[x][y] == '#')
        return 0;
    if (x >= h || y >= w)
        return 0;

    if (dp[x][y] == ROCKY)
        dp[x][y] = (ans(x + 1, y) + ans(x, y + 1)) % MOD;
    return dp[x][y];
}

int32_t main()
{
    ios::sync_with_stdio(false);
    init();
    r2(h, w);
    
    repeat(i, h)
        repeat(j, w)
            r(grid[i][j]);
    
    pn(ans(0, 0));
    return 0;
}



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

#define int long long
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            for(int k = j + 1; k < n; k++) {
                if(a[i] == a[j] or a[i] == a[k] or a[j] == a[k]) continue;
                if(a[i] + a[j] > a[k] and a[i] + a[k] > a[j] and a[j] + a[k] > a[i]) {
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3656
#include"bits/stdc++.h"

using namespace std;

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

	vector<int>B(M);
	int A[100][100];

	for (int i = 0; i < M; i++) {
		cin >> B[i];
	}

	int ans = 0;
	for (int i = 0; i < N; i++) {
		int sum = 0;
		for (int j = 0; j < M; j++) {
			cin >> A[i][j];
			sum += A[i][j] * B[j];
		}
		sum += C;
		if (sum > 0) {
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
 
using namespace std;
 
const int vy[] = {0, 1, 0, -1}, vx[] = {1, 0, -1, 0};
 
int H, W;
string S[40];
bool v[40][40];
 
void dfs(int y, int x)
{
  v[y][x] = true;
  if(S[y][x] == '*') return;
  if(S[y][x] == '#') S[y][x] = '.';
  for(int i = 0; i < 4; i++) {
    int ny = vy[i] + y, nx = vx[i] + x;
    if(ny < 0 || nx < 0 || ny >= H || nx >= W) continue;
    if(S[ny][nx] == '.') continue;
    if(v[ny][nx]) continue;
    dfs(ny, nx);
    return;
  }
  return;
}
 
int main()
{
  cin >> H >> W;
  int sy, sx;
  for(int i = 0; i < H; i++) {
    cin >> S[i];
    for(int j = 0; j < W; j++) {
      if(S[i][j] == '@') {
        sy = i;
        sx = j;
      }
    }
  }
 
  for(int j = 0; j < W; j++) {
    if(S[0][j] == '.') S[0][j] = '#';
  }
  if(S[1][0] == '.') S[1][0] = '#';
  if(S[1][W - 1] == '.') S[1][W - 1] = '#';
  for(int i = 2; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(j % 2 == 0) {
        if(S[i][j] == '.') S[i][j] = '#';
      } else {
        if(i == 2 && j % 4 == 3) S[i][j] = '#';
        else if(i == H - 1 && j % 4 == 1) S[i][j] = '#';
      }
    }
  }
 
  dfs(sy, sx);
 
  for(int i = 0; i < H; i++) {
    cout << S[i] << endl;
  }
}

Measured memory_bytes: 3204
n = int(input())

sosu = []
#エラトステネスの篩
primes = list(range(n+1))
primes[1] = 0
for i in range(2,int(n**.5)+1):
    if primes[i]!=0:
        for j in range(i*2,n+1,i):
            primes[j] = 0
primes = [prime for prime in primes if prime!=0]

power = []
for prime in primes:
    p = prime
    tmp = 0
    while p<=n:
        tmp += n // p
        p *= prime
    power.append(tmp)
#print(power)

res = 1
mod = 10**9+7
for i in power:
    res *= i + 1
    res %= mod

print(res)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int N;
  cin>>N;
  int k=0;
  for(int j=1;j<=N;j++)
    for(int i=1;i*j<=N;i++)
      k+=i*j;
  cout<<k<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    long long r, g, b, t, flag = 0;
    cin >> r >> g >> b >> t ;
    
    for(int i = 0; i < t; i++){
        if (b <= r || b <= g){
            b = b * 2;
        } else if(g <= r){
            g = g * 2;
        } 
        
        //printf("%lld %lld %lld\n", r, g, b);

        if(r < g && g < b){
            flag++;
            break;
        }
        
    }
    
    if(flag > 0){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
}


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

#ifndef ONLINE_JUDGE
#define debarr(a,x,y)cerr<<#a<<":";for(int i=x;i<=y;i++)cerr<<a[i]<<" ";cerr<<endl;
#define debmat(mat,row,col)cerr<<#mat<<":\n";for(int i=0;i<row;i++){for(int j=0;j<col;j++)cerr<<mat[i][j]<<" ";cerr<<endl;}
#define deb(...)dbs(#__VA_ARGS__,__VA_ARGS__)
template<class S, class T>ostream &operator<<(ostream &os, const pair<S, T> &p) {return os << "(" << p.first << "," << p.second << ")";}
template<class T>ostream &operator<<(ostream &os, const vector<T> &p) {os << "["; for (auto&it : p)os << it << " "; return os << "]";}
template<class T>ostream &operator<<(ostream &os, const set<T>&p) {os << "["; for (auto&it : p)os << it << " "; return os << "]";}
template<class T>ostream &operator<<(ostream &os, const multiset<T>&p) {os << "["; for (auto&it : p)os << it << " "; return os << "]";}
template<class S, class T>ostream &operator<<(ostream &os, const map<S, T>&p) {os << "["; for (auto&it : p)os << it << " "; return os << "]";}
template<class T>void dbs(string str, T t) {cerr << str << ":" << t << "\n";}
template<class T, class...S>void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << ":" << t << ","; dbs(str.substr(idx + 1), s...);}
#else
#define deb(...){}
#define debarr(a,x,y){}
#define debmat(mat,row,col){}
#endif
#define pr(x) {cout << x << "\n"; return;}
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }

#define int              long long
#define ld               long double
#define fi               first
#define se               second
#define mp               make_pair
#define pb               push_back
#define rep(i,n)         for(int i=0;i<n;i++)
#define re(i,n)          for(int i=1;i<=n;i++)
#define fr(i,a,b)        for(int i=a;i<=b;i++)
#define fb(i,a,b)        for(int i=a;i>=b;i--)
#define sz(x)            (int)x.size()
#define all(x)           x.begin(),x.end()
#define ini(x,y)         memset(x,y,sizeof(x))
typedef vector<int>      vi;
typedef pair<int, int>   pii;
typedef vector<pii>      vii;
typedef map<int, int>    mii;
typedef set<int>         si;
const int N = 2e5 + 10;


void solve(int tc)
{
	int n; cin >> n;
	int ans = 0;
	re(i, n - 1)
	{
		ans += (n - 1) / i;
	}
	cout << ans << endl;

}




signed main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t = 1;
	//cin >> t;
	for (int i = 1; i <= t; i++) solve(i);
	return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
#define MAX 200001

int a[MAX],y[MAX],p[MAX],li[MAX];

void dps(int ind, int sum){
  li[ind] = sum + p[ind];
  int r = a[ind];
  while(r != -1){
    dps(r,li[ind]);
    r = y[r];
  }
  return;
}

int main(){
  int n,q,t0,t1,
      i;
  
  scanf("%d%d",&n,&q);
  
  for(i=1;i<=n;i++)a[i] = -1;
  for(i=1;i<=n;i++)y[i] = -1;
  for(i=1;i<n;i++){
    scanf("%d%d",&t0,&t1);
    y[t1] = a[t0];
    a[t0] = t1;
  }
  
  for(i=1;i<=n;i++)p[i] = 0;
  for(i=0;i<q;i++){
    scanf("%d%d",&t0,&t1);
    p[t0] += t1;
  }
  
  dps(1,0);
  
  for(i=1;i<=n;i++){
    printf("%d ", li[i]);
  }
  return 0;
}

Measured memory_bytes: 11648
N, K = map(int, input().split())

p = 0.0
for n in range(1, N + 1):
    if K <= n:
        p += 1 / N
    else:
        t = 0
        while n < K:
            n <<= 1
            t += 1
        p += 1 / N * 0.5 ** t
print(p)

Measured memory_bytes: 39152
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

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

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())



def main():
    n,m = map(int, input().split())
    uf = UnionFind(n)

    for _ in range(m):
        x,y,z = map(int, input().split())
        # if z%2 == 0:
        uf.union(x-1, y-1)
    print(uf.group_count())


if __name__ == "__main__":
    main()

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define loop for(;;)
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;
#define inf (1e9)
#define eps (1e-9)

template<class S, class T> inline
ostream& operator<<(ostream&os, pair<S,T> p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template<class S, class T, class U> inline
ostream& operator<<(ostream&os, tuple<S,T,U> t) {
  return os << '('
    << get<0>(t) << ", "
    << get<1>(t) << ", "
    << get<2>(t) << ')';
}

template<class T> inline
ostream& operator<<(ostream&os, vector<T> v) {
  if (v.size() == 0) { return os << "(empty)"; }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

template<class T> inline
istream& operator>>(istream&is, vector<T>&v) {
  rep (i, v.size()) is >> v[i];
  return is;
}

int main() {
  long
  double x0,y0,x1,y1,x2,y2,x3,y3;
  while (cin>>x0>>y0>>x1>>y1>>x2>>y2>>x3>>y3) {
    long
    double dx0 = x1 - x0,
           dy0 = y1 - y0,
           dx1 = x3 - x2,
           dy1 = y3 - y2;
    // trace((dx0 * dx1 + dy0 * dy1));
    // trace(abs(dx0 * dx1 + dy0 * dy1));
    // trace(labs(dx0 * dx1 + dy0 * dy1));
    string str =
      (abs(dx0 * dx1 + dy0 * dy1) < 1e-13)
      ? "YES"
      : "NO";
    cout << str << endl;
  }

  return 0;
}

Measured memory_bytes: 1236
// Problem : C - XYZ Triplets
// Contest : AtCoder - AIsing Programming Contest 2020
// URL : https://atcoder.jp/contests/aising2020/tasks/aising2020_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,b,a) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define bug(x) cout<<#x<<"="<<x<<endl; 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy
 
int main() 
{
	// && has higher precedence than ||
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
	int N;
	cin>>N;
	vi ans(N+1);
	FOR(x,1,sqrt(N)+1)
	{
		FOR(y,x,sqrt(N)+1)
		{
			if(x*x+y*y+x*y+y+x>N)
				break;
			FOR(z,y,sqrt(N)+1)
			{
				int val=x*x+y*y+z*z+x*y+x*z+y*z;
				if(val>N)
					break;
				if(x==y && y==z)
					ans[val]++;
				else if(x==y || y==z || x==z)
					ans[val]+=3;
				else
					ans[val]+=6;
			}
		}
	}
	F0R(x,N)
		cout<<ans[x+1]<<nl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3648
z=[]
a=input()
for i in a:
    z.append(i)

if (z[0]=='R') and (z[1]=='R') and (z[2]=='S'):
        print(2)
elif (z[1]=='R') and (z[2]=='R') and (z[0]=='S'):
        print(2)
elif (z[0]=='S') and (z[1]=='S') and (z[2]=='S'):
        print(0)
elif (z[0]=='R') and (z[1]=='R') and (z[2]=='R'):
        print(3)
else: 
    print(1)

Measured memory_bytes: 9088
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);
        
        int S = scanner.nextInt();
        
        int h,m,s;
        
        h = S/3600;
        
        m = S%3600/60;
        
        s = S%3600%60;
        
        
        
        System.out.println(h + ":" + m + ":" + s);
    }
}



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

int main(){
 
    int k, a, b, m = 0;
    cin >> k >> a >> b;
    
    int x = a / k, y = b / k;
    
    m = abs(x - y);
    
    m = ( a % k == 0 ? m + 1 : m );
    
    if ( m > 0 )
        cout << "OK" << endl;
    else
        cout << "NG" << endl;

    
    // for ( int i = a; i <= b; i++ ){
    //     if ( i % k == 0 ){
    //         cout << "OK" << endl;
    //         return 0;
    //     }
    // }
    
    
    
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>

using namespace std;

int N,K;
string s;

int main(){
    cin >> N >> K;
    cin >> s;
    char c = s[0];
    char d;
    int k =0;
    int score = 0;
    if(s[0]==s[1] && s[0] == 'R') score++;
    if(s[N-2]==s[N-1] && s[N-1] == 'L') score++;
    for(int i=1;i<N-1;i++){
        int p = 1;
        if(s[i]=='L') p*=(-1);
        if(s[i] == s[i+p]) score++; 
    }
    for(int i=1;i<N;i++){
        if(c == s[i]) continue;
        d = s[i];
        for(;i<N;i++){
            if(d != s[i]) break;
        }
        if(i == N){
            score++;
            break;
        } 
        score += 2;
        k++;
        if(k==K) break;
    }
    cout << score << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>

using namespace std;

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

	string s;
	long long name[5] = {};
	for (int i = 0; i < n; i++) {
		cin >> s;

		switch (s[0]) {
		case 'M':
			name[0]++;
			break;
		case 'A':
			name[1]++;
			break;
		case 'R':
			name[2]++;
			break;
		case 'C':
			name[3]++;
			break;
		case 'H':
			name[4]++;
			break;
		}
	}

	long long ans = 0;
	for (int i = 0; i < 5; i++) {
		for (int j = i + 1; j < 5; j++) {
			for (int k = j + 1; k < 5; k++) {
				ans += name[i] * name[j] * name[k];
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())

if K>(N-1)*(N-2)//2:
    print(-1)
    exit()
    
edges = []

for i in range(1, N):
    edges.append((i, N))
    
cnt = 0

for i in range(1, N):
    for j in range(i+1, N):
        if cnt==(N-1)*(N-2)//2-K:
            break
        
        edges.append((i, j))
        cnt += 1

print(len(edges))

for ui, vi in edges:
    print(ui, vi)

Measured memory_bytes: 43120
#include<bits/stdc++.h>
#define __  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;


int main()
{ __;

    string s;
    cin>>s;
    int y=0,m=0;
    for(int i=0;i<4;i++)
    {
       y=(s[i]-'0') + (10*y);
    }
    m=(s[5]-'0');
    m=(s[6]-'0') + (10*m);
    if(y<2019 || (y==2019 && m<=4)){
            cout<<"Heisei";
    }
    else cout<<"TBD";

    return 0;
}


Measured memory_bytes: 256
N, x = map(int, input().split())

a = list(map(int, input().split()))

ans = 0
for i in range(N-1):
    if a[i]+a[i+1] > x:
        if -a[i]+x > 0:
            ans += a[i+1]+a[i]-x
            a[i+1] = x-a[i]
        else:
            ans += a[i+1]
            a[i+1] = 0
            ans += a[i]-x
            a[i] -= a[i]-x

    # print(i)
    # print(a)
    # print(ans)

print(ans)

Measured memory_bytes: 19944
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  lol n, a[100005];
  cin >> n;
  lol ans = 1;
  rep(i, n){
    cin >> a[i];
  }
  sort(a, a +n);
  rep(i, n){
    if(a[i] * ans > 1000000000000000000 || (a[0] != 0 && ans * a[i] < ans)){
      cout << -1 << '\n';
      return 0;
    }
    ans *= a[i];
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 4444
from collections import defaultdict
from bisect import bisect_right

s = input()
ns = len(list(s))
t = input()
nt = len(list(t))

jisho = defaultdict(list)


# sの何文字目かどうかのidxを集める
for i in range(ns):
    jisho[s[i]].append(i)

# jishoにない→構成不可能
# 二分探索して今のidxより大きい値を取る。
# 今の値が一番大きいときは0からやり直す。
# 出力するのは先頭から何文字目か
now = -1  # bisect用の現在地
cnt = 0  # 何周したか
for i in range(nt):
    lis = jisho[t[i]]
    if not lis:
        print(-1)
        exit()
    pos = bisect_right(lis, now)
    # print(t[i], now, pos)
    # ここで復習、bisect_right はnow以下のものの個数。
    if pos == len(lis):
        now = -1
        cnt += 1
        pos = bisect_right(lis, now)
    now = lis[pos]
print(cnt * ns + now + 1)



Measured memory_bytes: 85440
def check(a, b):
    k = 1
    res = 0
    if a == b and (a <= N): res += 1
    while True:
        if (a * (10 ** k) + b) > N:
            break
        else:
            if len(str(N)) > (k+1) or str(N)[0] > str(a):
                res += 10 ** (k - 1)
                k += 1
                continue

            else :
                Q = N - (a * (10 ** k) + b)
                p = 1
                if len(str(Q)) > 1 :
                    p += (int(str(Q)[:-1]))
                res += p
                k += 1
    return res


def main():
    global N
    N = int(input())
    ans = 0
    for i in range(1, 10, 1):
        for j in range(1, 10, 1):
            a = check(i, j)
            b = check(j, i)
            ans += a * b
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int count=0,x=0;
        while(true){
            x=sc.nextInt();
            count++;
            if(x==0) break;
            else{
                System.out.println("Case "+count+": "+x);
                
            }
        }
    }
}


Measured memory_bytes: 41676
S = input()

max_count = 0
counter = 0
last_s_is_ACGT = False
for i in range(len(S)):
    if S[i] in ["A", "C", "G", "T"]:
        counter += 1
        if counter > max_count:
            max_count = counter
    else:
        counter = 0

print(max_count)

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, char, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

const ll mod = 1000000007;

static const ll INF = 1e15;

typedef ll Weight;
struct Edge {
	int from, to;
	Weight weight;
	Edge(int src, int dst) :
		from(src), to(dst), weight(0) { }

	Edge(int src, int dst, Weight weight) :
		from(src), to(dst), weight(weight) { }
};
bool operator < (const Edge& e, const Edge& f) {
	return e.weight != f.weight ? e.weight > f.weight :
	e.from != f.from ? e.from < f.from : e.to < f.to;
}

struct UndirectionalCompare {
	bool operator() (const Edge& e, const Edge& f) const {
		if (min(e.from, e.to) != min(f.from, f.to))
			return min(e.from, e.to) < min(f.from, f.to);
		return max(e.from, e.to) < max(f.from, f.to);
	}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;
typedef set<Edge, UndirectionalCompare> Edgeset;

struct graph_diameter {
	typedef pair<Weight, int> Result;
	Result visit(int p, int v, const Graph& g) {
		Result r(0, v);
		for (auto e : g[v]) if (e.to != p) {
			Result t = visit(v, e.to, g);
			t.first += e.weight;
			if (r.first < t.first) r = t;
		}
		return r;
	}
	Weight diameter(const Graph& g) {
		Result r = visit(-1, 0, g);
		Result t = visit(-1, r.second, g);
		return t.first; // (r.second, t.second) is farthest pair
	}

};

int main(void)
{
	int v;
	cin >> v;
	Graph g(v);
	int e = v - 1;
	rep(i, e) {
		int s, t, w;
		cin >> s >> t >> w;
		g[s].push_back({ s,t,w });
		g[t].push_back({ t,s,w });
	}

	graph_diameter d;
	auto r = d.diameter(g);
	cout << r << endl;
	return 0;
}



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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

#ifdef LOCAL
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else 
#define dump(x) true
#endif

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

int H, W;

bool f[1024][1024];
bool xo[10][10];

int calc() {
	rep(i, H) {
		rep(j, W) {
			xo[i+1][j+1] = xo[i+1][j]^xo[i][j+1]^xo[i][j]^f[i][j];
		}
	}

	int s = 0;

	rep(i, H) {
		rep(j, W) {
			rep(k,i+1) {
				rep(l,j+1) {
					if (xo[i+1][j+1]^xo[i+1][l]^xo[k][j+1]^xo[k][l]) {
						++s;
					}
				}
			}
		}
	}
	return s;
}

void out(V<int> vec) {
	for (int mask : vec) {
		cerr<<"Case!"<<endl;
		int now = 0;
		rep(i, H) {
			string t(W, ' ');
			rep(j, W) {
				f[i][j] = (mask >> now) & 1;
				t[j] = '0' + f[i][j];
				now++;
			}
			cout << t << "\n";
		}
	}
}

void solve(int h, int w) {
	int mh = h / 2, mw = w / 2;
	if (h == 1 && w == 1) {
		f[0][0] = 1;
		return ;
	}

	if (h == 1) {
		solve(h, w / 2);
		f[0][mw] = 1;
		for (int j = mw + 1; j < w; ++j) {
			f[0][j] = f[0][w-1-j];
		}
		return ;
	}
	if (w == 1) {
		solve(h / 2, w);

		f[mh][0] = 1;
		for (int i = mh + 1; i < h; ++i) {
			f[i][0] = f[h-1-i][0];
		}
		return ;		
	}
	solve(h / 2, w / 2);

	for (int i = mh + 1; i < h; ++i) {
		rep(j, mw) {
			f[i][j] = f[h-1-i][j];
		}
	}
	rep(i, h) {
		for (int j = mw + 1; j < w; ++j) {
			f[i][j] = f[i][w-1-j];
		}
	}
	f[mh][mw] = 1;
}

int main() {
	int N, M; cin >> N >> M;
	H = (1<<N)-1;
	W = (1<<M)-1;

/*
	int mx = -1;
	V<int> mask;
	rep(b, 1 << (H * W)) {
		int now = 0;
		rep(i, H) {
			rep(j, W) {
				f[i][j] = (b >> now) & 1;
				now++;
			}
		}
		int r = calc();
		if (r > mx) {
			mx = r;
			mask.clear();
			mask.pb(b);
		} else if (r == mx) {
			mask.pb(b);
		}
	}
	out(mask);*/
	solve(H, W);
	int now = 0;

	rep(i, H) {
		string t(W, ' ');
		rep(j, W) {
			t[j] = '0' + f[i][j];
			now++;
		}
		cout << t << "\n";
	}

	return 0;
}

Measured memory_bytes: 2304
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	x, k := nextInt(), nextInt()

	m := x % k
	if m > abs(m-k) {
		m = abs(m - k)
	}
	fmt.Fprint(out, m)
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func split(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}

// -*-*-*-*-*-*-*-*-
// * tool snippets *
// -*-*-*-*-*-*-*-*-
func duplicate2Int(base [][]int) (ret [][]int) {
	ret = make([][]int, len(base))
	for i, v := range base {
		ret[i] = append([]int{}, v...)
	}
	return
}

// -*-*-*-*-*-*-*-*-*-*-*-*-*-
// * Algorithms Utility Zone *
// -*-*-*-*-*-*-*-*-*-*-*-*-*-

// -*-*-*-*-*-*-*-
// * 1. nibutan  *
// -*-*-*-*-*-*-*-
func lower_bound(arr []int, target int) int {
	l, r := 0, len(arr)
	for l < r {
		mid := (l + r) / 2
		if arr[mid] < target {
			l = mid + 1
		} else {
			r = mid
		}
	}
	return l
}

func upper_bound(arr []int, target int) int {
	l, r := 0, len(arr)
	for l < r {
		mid := (l + r) / 2
		if target < arr[mid] {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l
}

// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// * math flavor typical theories *
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
func gcd(a, b int) int {
	if a > b {
		return gcd(b, a)
	}
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

func pow(a, b int) (ret int) {
	ret = a
	// 10^2 = 100ってことは10に10を1回掛けることだね
	// なので初期値を含めると上限b-1未満
	for i := 0; i < b-1; i++ {
		ret *= a
	}
	return
}

func powMod(n, m, mod int) (ret int) {
	ret = 1
	for m > 0 {
		if m&1 == 1 {
			ret *= n
			ret %= mod
		}
		n *= n
		n %= mod
		m >>= 1
	}
	return ret
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>

using namespace std;

int main(void){
  int A,B,C,X,Y,ans,tmp,x,y,z;
  scanf("%d%d%d%d%d",&A,&B,&C,&X,&Y);
  ans = A*X+B*Y;
  x=X;
  y=Y;
  z=0;
  if(2*C < A+B){
    while(x >= 0 || y >= 0){
      x--;
      y--;
      z++;
      tmp = A*max(0,x)+B*max(0,y)+2*C*z;
      if(tmp < ans){
        ans = tmp;
      }
    }
  }
  printf("%d\n",ans );
  return 0;

}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat Oct 27 19:18:58 2018
tenka1C
@author: maezawa
"""

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

a.sort()
b = [2*(-1)**i for i in range(n)]
b[0] = b[0]//2
b[-1] = b[-1]//2
b.sort()
ans1 = sum([a[i]*b[i] for i in range(n)])
c = [-b[i] for i in range(n)]
c.sort()
ans2 = sum([a[i]*c[i] for i in range(n)])
                    
print(max([ans1,ans2]))

    
    

Measured memory_bytes: 12484
#include <stdio.h>

int main(void){
	int a,b,c;
	
	if(scanf("%d %d %d",&a,&b,&c)>0){
		if(b-a == c-b){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}
	return 0;
}	

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int ans =0;
  cin >> s;
  for(int i=0;i<(s.size()+1)/2;i++){
    if(s[i]!=s[s.size()-1-i])ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k;
  cin>>n>>k;
  priority_queue<int,vector<int>,greater<int>> pq;
  for(int i=0;i<n;i++){
    int r;
    cin>>r;
  	 pq.push(r);
  }
  int sum=0;
  while(k--){
  	sum+=pq.top();
    pq.pop();
  }
  cout<<sum;
}

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

bool dfs(int N, vector<vector<bool>> &field, vector<bool> &visited, int s) {
  visited.at(s) = true;
  for (int next; next < N; next++) {
    if (!field.at(s).at(next)) continue;
    if (visited.at(next)) continue;
    dfs(N, field, visited, next);
  }
  bool flag = false;
  for (int i; i < N; i++) {
    if (!visited.at(i)) flag = true;
  }
  return flag;
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> edge(M);
  vector<vector<bool>> field(N, vector<bool>(N, false));
  for (int i = 0; i < M; i++) {
    int a, b; cin >> a >> b;
    edge.at(i) = make_pair(a-1, b-1);
    field.at(a-1).at(b-1) = true;
    field.at(b-1).at(a-1) = true;
  }
  int ans = 0;
  for (int i = 0; i < M; i++) {
    int a = edge.at(i).first;
    int b = edge.at(i).second;
    field.at(a).at(b) = false;
    field.at(b).at(a) = false;
    vector<bool> visited(N, false);
    if (dfs(N, field, visited, 0)) ans++;
    field.at(b).at(a) = true;
    field.at(a).at(b) = true;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    string s, t;
    cin >> s >> t;
    int sn = s.length(), tn = t.length();

    vector<vector<int>> dp(sn + 3, vector<int>(tn + 3));
    vector<vector<pii>> rec(sn + 3, vector<pii>(tn + 3));
    for (int i = 1; i <= sn; ++i) {
        for (int j = 1; j <= tn; ++j) {
            dp[i][j] = dp[i - 1][j];
            rec[i][j] = {i - 1, j};
            if (dp[i][j] < dp[i][j - 1]) {
                dp[i][j] = dp[i][j - 1];
                rec[i][j] = {i, j - 1};
            }
            if (s[i - 1] == t[j - 1] && dp[i][j] < dp[i - 1][j - 1] + 1) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
                rec[i][j] = {i - 1, j - 1};
            }
        }
    }

    int idx1 = sn, idx2 = tn;
    string ans;
    while (idx1 > 0 && idx2 > 0) {
        auto [pr1, pr2] = rec[idx1][idx2];
        if (pr1 == idx1 - 1 && pr2 == idx2 - 1)
            ans.push_back(s[pr1]);
        idx1 = pr1, idx2 = pr2;
    }

    reverse(ans.begin(), ans.end());
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 109068