akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<pair<long long, long long>>>;

Graph g;
vector<long long> dist;

void dfs(long long cv, long long pv, long long d)
{
	dist[cv] = d;

	for (auto e : g[cv])
	{
		if (e.first == pv) continue;
		dfs(e.first, cv, d+e.second);
	}
}

int main(int argc, char **argv)
{
	long long n; cin >> n;
	vector<long long> u(n-1), v(n-1), w(n-1);
	for (long long i = 0; i < n-1; ++i) cin >> u[i] >> v[i] >> w[i];

	vector<long long> ans(n+1);
	g.resize(n+1); dist.resize(n+1, -1);
	for (long long i = 0; i < n-1; ++i)
	{
		g[u[i]].push_back(pair<long long, long long>(v[i], w[i]));
		g[v[i]].push_back(pair<long long, long long>(u[i], w[i]));
	}
	dfs(1, -1, 0);

	for (long long i = 1; i < n + 1; ++i) ans[i] = dist[i] % 2;

	for (long long i = 1; i < n + 1; ++i)
		std::cout << ans[i] << std::endl;
}


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

using static Input;
using static Util;
class Program
{
    static int AC,WA,TLE,RE ;
    static void INPUT()
    {
        var N = NextInt();
        for (int i = 0; i < N; i++)
        {
            switch (NextString())
            {
                case "AC": AC++; break;
                case "WA": WA++; break;
                case "TLE": TLE++; break;
                case "RE": RE++; break;
            }
        }
    }

    static void OUT()
    {
        Console.WriteLine(string.Format("AC x {0}", AC));
        Console.WriteLine(string.Format("WA x {0}", WA));
        Console.WriteLine(string.Format("TLE x {0}", TLE));
        Console.WriteLine(string.Format("RE x {0}", RE));
    }

    static void Main(string[] args)
    {
#if DEBUG  
        //TESTINPUT();
        INPUT();

#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{
}


Measured memory_bytes: 22012
def main():
    n = int(input())
    ds = list(map(int, input().split()))
    cs = [0] * 100001
    for d in ds:
        cs[d] += 1
    abc = 0
    res = 0
    for k in range(2, 100001):
        abc += cs[k - 1]
        if abc * 2 == n:
            res += 1
        elif abc * 2 > n:
            break
    print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 14396
//Bismillah Hir Rehmanir Rahim
//Allah knows best
using namespace std;
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#define endl "\n"
#define mini -10000000000000000
#define start ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f(i, a, n) for( i=a; i<n;i++)
#define ll long long
#define pi 3.141592653589793
#define vi              vector<int>
#define si              set<int>
#define pb              push_back
#define mp              make_pair
#define mod             1000000007
#define rr              return 0
#define ff              first
#define in              insert
#define ss              second
#define setbits(x)      __builtin_popcountll(x)
#define zrbits(x)       __builtin_ctzll(x)
#define deb(x)          cout << #x << " = " << x << endl
#define set_bit(x, idx) x = x|1LL<<idx
#define check_bit(x, idx) min(x&(1LL<<idx),1LL)
#define toggle_bit(x, idx) x = x^(1LL<<idx)
int main()
{
    start;
   // freopen("input.txt","r",stdin);
    ll i,j,n,m;
    string s;
    cin>>n;
    s="ACL";
    ll cnt=0;
    for(i=0;i<n;i++)
    {
      cout<<s;  
    }
    rr;
}

Measured memory_bytes: 3608
<?php

// fscanf(STDIN, "%t", $t);

$s               = explode(' ', trim(fgets(STDIN)))[0];
$t               = explode(' ', trim(fgets(STDIN)))[0];

$s_len           = strlen($s); 
$t_len           = strlen($t); 
$max_match_count = 0;
$match_index     = 0;

for ($i=0; $i <= $s_len - $t_len; $i++) { 
    $match_count = 0;
    for ($j=0; $j < $t_len; $j++) { 
        if($s[$j + $i] === $t[$j]){
           $match_count++;
        }
    }
    if ($max_match_count < $match_count){
        $max_match_count = $match_count;
        $match_index = $i;
    }
}

$change_count = 0;
for ($i=0; $i < $t_len; $i++) { 
    if($s[$i + $match_index] !== $t[$i]){
        $change_count++;
    }
}
echo $change_count;

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


int main() {
  
  string s, t;
  
  cin >> s;
  cin >> t;
  
  sort(s.begin(), s.end());
  
  sort(t.begin(), t.end());
  reverse (t.begin(), t.end());
  
  if (s < t) cout << "Yes" << endl;
  else cout << "No" << endl;
 
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc170/tasks/abc170_f

#include <bits/stdc++.h>
using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DEBUG 0
#if DEBUG
  #define _GLIBCXX_DEBUG
  #define DUMP(a) REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " ")
  #define DUMP2D(b) REP(_j, b.size()) DUMP(b[_j]); cout << endl
#else
  #define DUMP(a)
  #define DUMP2D(b)
#endif

const int H_MAX = 1e6;
const int W_MAX = 1e6;
const int K_MAX = 1e6;
const int INF = 1e9;
const int D[4][2] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};

using P = pair<int, int>;

int H, W, K;
int x_1, y_1, x_2, y_2;
vector<string> c;
vector<vector<int>> d;

int bfs() {
  queue<P> que;
  que.push({x_1, y_1});
  d = vector<vector<int>>(H, vector<int>(W, INF));
  d[x_1][y_1] = 0;
  while (!que.empty()) {
    P p = que.front(); que.pop();
    int i = p.first;
    int j = p.second;
    if (i == x_2 && j == y_2) break;
    REP(k, 4) {
      int i2 = i;
      int j2 = j;
      FOR(l, 1, K) {
        i2 += D[k][0];
        j2 += D[k][1];
        if (i2 < 0 || i2 >= H || j2 < 0 || j2 >= W) break;
        if (c[i2][j2] == '@' || d[i2][j2] <= d[i][j]) break;
        if (d[i2][j2] < INF) continue;
        que.push({i2, j2});
        d[i2][j2] = d[i][j] + 1;
      }
    }
  }
  return d[x_2][y_2];
}

int main() {
  cin >> H >> W >> K;
  cin >> x_1 >> y_1 >> x_2 >> y_2;
  x_1--; y_1--; x_2--; y_2--;
  c = vector<string>(H);
  REP(i, H) cin >> c[i];

  int ans = bfs();
  DUMP2D(d);
  if (ans < INF) cout << ans << endl;
  else cout << -1 << endl;
}


Measured memory_bytes: 12168
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;



int main() {

	int n, m;
	cin >> n >> m;
	vector<vector<pii>> g(n);
	for (int i = 0; i < m; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		g[a].emplace_back(make_pair(b, -c));
	}

	vector<ll> d(n, BIG_NUM);
	d[0] = 0;
	bool isInf = false;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n;j++) {
			if (d[j] != BIG_NUM) {
				for (pii e : g[j]) {
					if (d[e.first] > d[j] + e.second) {
						d[e.first] = d[j] + e.second;
						if (i == n - 1 && (e.first == n-1 || j == n-1)) {
							isInf = true;
						}

					}
				}
			}
		}
	}
	if (isInf) {
		cout << "inf"<< endl;
	}
	else {
		cout << -d[n - 1] << endl;
	}
}





Measured memory_bytes: 256
n, r=map(int, input().split())
for x in range(n+1):
  for y in range(n+1):
    z=n-x-y
    if 0<=z<=n and 10000*x+5000*y+1000*z==r:
      print(x, y, z)
      exit()
print(-1, -1, -1)
      
      

Measured memory_bytes: 40812
#include <bits/stdc++.h>
 
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int k,n,a[200005];
void solve(){
    cin>>k>>n;
    rep(i,0,n) cin>>a[i];
    int mx=a[0]+k-a[n-1];
    rep(i,1,n) mx=max(mx,a[i]-a[i-1]);
    cout<<k-mx<<endl;
}
 
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
int n,m,s;
P t[1000000];
int main(){
  while(cin>>n&&n){
    for(int i=0;i<n;i++){
      cin>>t[i].second;
      t[i].first=0;
      for(int j=0;j<4;j++){
	cin>>m>>s;
	t[i].first+=(m*60+s);
      } 
    }
    sort(t,t+n);
    cout<<t[0].second<<endl;
    cout<<t[1].second<<endl;
    cout<<t[n-2].second<<endl;
  }
}

Measured memory_bytes: 8976
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    al=list(chr(ord('A')+i) for i in range(26))
    h,w=map(int, input().split())
    l=[list(input().split()) for i in range(h)]
    for hh in range(h):
        for ww in range(w):
            if l[hh][ww]=='snuke':
                print(al[ww]+str(hh+1))
resolve()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int n;
    cin >> n;
    vi v(n);
    rep(i, n) cin >> v[i];
    vi idx(n);
    rep(i, n) idx[i] = i;
    sort(all(idx), [&](int a, int b) {return v[a] < v[b];});
    rep(i, n) {
        cout << idx[i]+1 << (i == n-1?'\n':' ');
    }
    return 0;
}

Measured memory_bytes: 1536
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let k: usize = read!();

    if k % 2 == 0 {
        println!("{}", -1);
        std::process::exit(0);
    }

    let mut i = 1;
    let mut num = 7 % k;
    let mut mods = vec![false; k + 1];
    
    mods[num] = true;

    while num != 0 {
        num = (num * 10 + 7) % k;

        if mods[num] {
            println!("{}", -1);
            std::process::exit(0);
        }

        mods[num] = true;
        i += 1;
    }

    println!("{}", i);
}


Measured memory_bytes: 3032
import java.io.PrintWriter;
import java.util.*;

public class Main {
	static final long MOD = 1000000007;
	static long[] rev2;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int B = sc.nextInt();
		int W = sc.nextInt();
		
		rev2 = new long[B+W+1];
		rev2[0] = 1;
		rev2[1] = rev(2);
		for(int i=2; i<=B+W; i++)
			rev2[i] = (rev2[i-1]*rev2[1])%MOD;
		
		long[] combB = createComb(B+W, B-1);
		long[] combW= createComb(B+W, W-1);
		
		long[] pB = new long[B+W+1];
		long[] pW = new long[B+W+1];
		
		for(int i=0; i<B+W; i++) {
			long ans = ((1-pB[i]-pW[i]+MOD+MOD)*rev2[1] + pW[i])%MOD;
			pw.println(ans);
			pB[i+1] = (pB[i] + combB[i]*rev2[i+1])%MOD;
			pW[i+1] = (pW[i] + combW[i]*rev2[i+1])%MOD;
		}
		
		sc.close();
		pw.close();
	}
	
	static long[] createComb(int N, int v) {
		long[] ans = new long[N+1];
		ans[v] = 1;
		for(int i=v; i<N; i++)
			ans[i+1] = (((ans[i]*(i+1))%MOD)*rev(i+1-v))%MOD;
		
		return ans;
	}
	
	static long rev(long a) {
		return pow(a, MOD-2);
	}
	
	static long pow(long a, long b) {
		long ans = 1;
		while(b>0) {
			if((b&1)!=0)
				ans = (ans * a)%MOD;
			b>>=1;
			a = (a*a)%MOD;
		}
		return ans;
	}

}


Measured memory_bytes: 50692
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main()
{
    int N, W;
    cin >> N >> W;
    vector<string>masu(N);
    for (int i=0; i<N; i++) {
        cin >> masu.at(i);
    }

    for (int i=0; i<=N+1; i++) {
        for (int j=0; j<=W+1; j++) {
            if (i == 0 || i == N+1 || j==0 || j==W+1) {
                cout << '#';
            } else {
                cout << masu[i-1][j-1];
            }
        }
        cout << endl;
    }
    return 0;
}

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

using namespace std;

#define ll long long
#define mk make_pair

void PLAY()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cout << fixed << setprecision(10);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

/*ll v[1000000];
ll len[1000000];
ll cnt = 0;
vector<vector<ll>> x;
ll dfs(ll n)
{
    //cout<<n<<" a"<<endl;
    vis[n] = 1;
    for (int i = 0; i < x[n].size(); i++)
    {
        ll lol = x[n][i];
        if (!vis[lol])
        {
            dfs(lol);
            cnt++;
        }
    }
    return cnt;
}
void seth(ll a, ll b)
{
    if (vis[a] == 2)
        return;
    vis[a] = 2;
    len[a] = b;
    for (int i = 0; i < x[a].size(); i++)
    {
        ll lol = x[a][i];
        if (vis[lol] != 2)
        {
            seth(lol, b);
        }
    }
    }*/

bool cmp(pair<ll, ll> &a, pair<ll, ll> &b)
{
    if (a.second != b.second)
    {
        return a.second < b.second;
    }
    return a.first < b.first;
}

const ll N = 1e5;
const ll mod = 1e18 + 9;

ll poww(ll b, ll p)
{
    if (p == 0)
        return 1;
    if (p % 2)
        return (poww(b, p - 1) * b) % mod;
    return (poww((b * b) % mod, p / 2)) % mod;
}

ll fact[N], infact[N];
ll ncr(ll n, ll r)
{
    return (((fact[n] * infact[r]) % mod) * infact[n - r]) % mod;
}

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

    ll n,m;
    cin>>n>>m;
    ll sum=0;
    for(int i=0;i<m;i++)
    {
        ll a;
        cin>>a;
        sum+=a;
    }
    if(sum>=n)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    

    return 0;
}


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

using namespace std;

int N;
map<string, int> BaseList;


void solve() {
	int m, num, sum;
	string name, tmp;

	/*for (map<string, int>::iterator it = BaseList.begin(); it!= BaseList.end(); ++it) {
		cout << it->first << " " << it->second << endl;
	}*/
	cin >> m;
	for (int i = 0; i < m; ++i) {
		cin >> name >> num;
		sum = 0;
		for (int j = 0; j < num; ++j) {
			cin >> tmp;
			sum += BaseList[tmp];
		}
		if (sum < BaseList[name]) {
			BaseList[name] = sum;
		}
	}
	cin >> name;
	cout << BaseList[name] << endl;
}

int main() {
	int value;
	string str;

	while (cin >> N, N) {
		BaseList.clear();
		for (int i = 0; i < N; ++i) {
			cin >> str >> value;
			BaseList[str] = value;
		}
		solve();
	}

	return 0;
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    REP(i, S.length()) {
        cout << "x";
    }
    cout << endl;
    return 0;
}

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

int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> ans(N, 0);
  for (int i = 1; i < N; ++i) cin >> A[i];

  for (int i = 1; i < N; ++i)
  {
    ans[A[i] - 1] += 1;
  }

  for (int i = 0; i < N; ++i)
  {
    cout << ans[i] << endl;
  }

  return 0;
}


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

void fizzbuzz(int64_t n, int64_t &ans)
{
    if (n > 1)
        fizzbuzz(n - 1, ans);

    if (n % 3 == 0 && n % 5 == 0);
    else if (n % 3 == 0);
    else if (n % 5 == 0);
    else // nが3の倍数でも5の倍数でもない
        ans += n;
}


int main()
{
    int64_t N;
    cin >> N;

    int64_t ans = 0;
    fizzbuzz(N, ans);

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

Measured memory_bytes: 34884
// IOI 2021
 
#include <bits/stdc++.h>
using namespace std;
 
#define endl "\n"
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1e9, MOD = 1e9 + 7;
 
/////////////////////////////////////////////////////////////////////
 
const int N = 1e3 + 5;

int FAC[N], INV[N], DP[N][N];

int Power(int a, int b) {
	int res = 1;
	for (; b; b >>= 1, a = 1LL * a * a % MOD) if (b & 1) res = 1LL * res * a % MOD;
	return res;
}
int C(int n, int k) { return (k > n ? 0 : 1LL * INV[k] * INV[n - k] % MOD * FAC[n] % MOD); }

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

	FAC[0] = 1;
	for (int i = 1; i < N; i++) FAC[i] = 1LL * FAC[i - 1] * i % MOD;
	INV[N - 1] = Power(FAC[N - 1], MOD - 2);
	for (int i = N - 2; i >= 0; i--) INV[i] = 1LL * INV[i + 1] * (i + 1) % MOD;

	int n, a, b, c, d; cin >> n >> a >> b >> c >> d;
	for (int i = 0; i < N; i++) DP[0][i] = 1;
	for (int i = a; i <= n; i++) for (int j = a; j <= b; j++) {
		DP[i][j] = DP[i][j - 1];
		for (int k = 1, p = 1; k <= d && i >= j * k; k++) {
			p = 1LL * p * C(i - (k - 1) * j, j) % MOD;
			if (k >= c) DP[i][j] = (DP[i][j] + 1LL * DP[i - j * k][j - 1] * p % MOD * INV[k] % MOD) % MOD;
		}
	}
	cout << DP[n][b] << endl;


	return 0;
}


Measured memory_bytes: 4224
#include<stdio.h>

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

int main(void){
  int n,i,tmp,ans=100000;
  scanf("%d",&n);
  
  char s[n];
  int a[n],b[n];
  for(i=0;i<n;i++){
    a[i]=0;
    b[i]=0;
  }
  
  scanf("%s",s);
  
  if(s[0]=='#') a[0]=1;
  if(s[n-1]=='.') b[n-1]=1;
  
  for(i=1;i<n;i++){
    if(s[i]=='#') a[i]=a[i-1]+1;
    else a[i]=a[i-1];
    if(s[n-1-i]=='.') b[n-1-i]=b[n-i]+1;
    else b[n-1-i]=b[n-i];
  }
  
  for(i=0;i<n;i++) ans=min(ans,a[i]+b[i]-1);
  
  printf("%d\n",ans);
  
  return 0;
}

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

using namespace std;

void solve()
{
	int N, K;
	cin >> N >> K;
	vector<unsigned long> imos(N+1), sums;
	for (int i = 0; i < N; i++)
	{
		long a;
		cin >> a;
		imos[i+1] = a+imos[i];
	}

	unsigned long ans = 0;

	for (int l = 0; l < N; l++) for (int r = l+1; r <= N; r++)
	{
		sums.push_back(imos[r] - imos[l]);
	}

	unsigned long b = 1ULL<<40;

	while(b>0)
	{
		int cnt = 0;
		for (auto s : sums)
		{
			cnt += ((ans+b)&s) == ans+b;
		}
		if (cnt >= K) ans += b;
		b >>= 1;
	}

	cout << ans << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


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

int main(){
  ll N;
  cin >> N;
  string ans;
  while (N > 0) {
    int res = N % 26;
    if (res == 0) {
      res = 26;
    }
    ans += (char)('a' + res - 1);
    N = (N - res) / 26;
  }
  reverse(ans.begin(), ans.end());
  cout << ans;
  return 0;
}

Measured memory_bytes: 3604
N = int(input())
A = list(input())
B = list(input())
C = list(input())

ans = 0

for i in range(N):
	if A[i] == B[i]:
		if A[i] == C[i]:
			pass
		else:
			ans += 1
	else:
		if A[i] == C[i]:
			ans += 1
		elif B[i] == C[i]:
			ans += 1
		else:
			ans += 2

print(ans)

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

#include<vector>
#include<string>

#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;
const ll INF = 1e9+1;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}

/*
m 
= a1k1+r1
= a2k2+r2 
= ...

という形だった時のr1+r2+...がfの値
min(mN - a1k1 - a2k2 - ... - aNkN | k1,k2...を自由に選ぶ) 
を、mを自由に選んだ時の最大値

多分違う: あるmが取れて、f(m)の値をfなるものにできるかどうかで二分探索?

Nが1なら簡単なんだ
a1-1(もしくはk*a1-1)を取ればf(m)の最大値はa1-1

Nが2のときは?
取りうる最大の値は(a1-1) + (a2-1) だが、これはa1=a1のときか
a1 = g*k1, a2 = g*k2と表されたとき、
g*k1*k2 + min(a1-1,a2-1) のmodは最大化されているのではないかという仮説
これも微妙であるからして

m mod ai の上界は ai - 1
m = a1 * a2 * ... * an - 1とすると一致
簡単じゃん..........
*/

ll N;

ll f(ll m, vector<ll> &a) {
    ll res = 0;
    for (ll i = 0; i < N; i++) {
        res += m % a[i];
    }
    return res;
}

int main() {
    cin >> N;
    vector<ll> a(N);
    ll res = 0;
    for (ll i = 0; i < N; i++) { 
        cin >> a[i];
        res += a[i]-1;
    }

    
    
    


    cout << res << endl;

}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cstdlib>
using namespace std;
int main(void)
{
	int a,b,c,x,h;
	cin>>a>>b>>h;
	if(a!=b)cout<<(a+b)*h/2<<endl;
	else cout<<a*h<<endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int k = in.nextInt();
		solve(n, k);
		in.close();
	}
 
	private static void solve(int n, int k) {
		int x = (n - 1) * (n - 2) / 2;
		if (k > x) {
			System.out.println(-1);
			return;
		}
      
      	System.out.println(n - 1 + x - k);
		for (int i = 2; i <= n; i++)
			System.out.println(1 + " " + i);
 
		for (int i = 2; i < n; i++)
			for (int j = i + 1; j <= n; j++) {
				if (k == x)
					return;
				x--;
				System.out.println(i + " " + j);
			}
	}
}

Measured memory_bytes: 23508
n=int(input())
s=[input() for i in range(n)]
s=sorted(s)
s.append('')
s1=s[0]
ans=['']
tmp=1
kaisu=0
for i in range(1,n+1):
    if s[i]==s1:
        #ひとつ前と同じものだったら回数を１増やす
        tmp+=1
    else:
        if kaisu<tmp:
        #これまでの要素の最高登場回数よりも
        # 当該要素の登場回数が多ければ
        # リストを書き換える
            ans=['']
            ans.append(s1)
            kaisu=tmp
        elif kaisu==tmp:
        #最高回数と等しければリストに追加する
            ans.append(s1)
        tmp=1
        s1=s[i]
        
for i in range(1,len(ans)):
    print(ans[i])

Measured memory_bytes: 20140
#include<stdio.h>

int main(void){
	int n[] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	int k;
	scanf("%d", &k);
	printf("%d", n[k - 1]);
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

//-----------------------------------------------------------------------------

int n,a[50];

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

	cin>>n;
	int mi=INF,ma=-INF,idx1=-1,idx2=-1;
	REP(i,n) {
		cin>>a[i];
		if(mi>a[i]) idx1=i,mi=a[i];
		if(ma<a[i]) idx2=i,ma=a[i];
	}
	if(mi>=0) {
		cout<<n-1<<endl;
		REP(i,n-1) cout<<i+1<<' '<<i+2<<endl;
	}
	else if(ma<=0){
		cout<<n-1<<endl;
		for(int i=n;i>1;i--) cout<<i<<' '<<i-1<<endl;
	}
	else {
		if(abs(mi)>abs(ma)) {
			cout<<2*n-2<<endl;
			REP(i,n) {
				if(i==idx1) continue;
				cout<<idx1+1<<' '<<i+1<<endl;
			}
			for(int i=n;i>1;i--) cout<<i<<' '<<i-1<<endl;
		}
		else {
			cout<<2*n-2<<endl;
			REP(i,n) {
				if(i==idx2) continue;
				cout<<idx2+1<<' '<<i+1<<endl;
			}
			REP(i,n-1) cout<<i+1<<' '<<i+2<<endl;
		}

	}

	return 0;
}


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

int main(){
  int N,M,l=0;
  cin >> N >>M;
  int r=N+1;
  for(int i=0;i<M;i++){
    int a,b;
    cin >> a >> b;
    l = max(l,a);
    r = min(r,b);
  }
  cout << max(r-l+1,0);
}
  

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int A;
int B;
int C;
int D;
int E;
int K;
int main(){
  rd(A);
  rd(B);
  rd(C);
  rd(D);
  rd(E);
  rd(K);
  if(E-A>K){
    wt_L(":(");
    wt_L('\n');
  }
  else{
    wt_L("Yay!");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190706-1

// --- original code ---
// int A, B, C, D, E, K;
// {
//   rd(A,B,C,D,E,K);
//   wt( if[E-A>K, ":(", "Yay!"] );
// }


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    int sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    bitset<4000005> dp;
    dp[0] = true;
    for (int i = 0; i < n; i++) {
        dp |= (dp << a[i]);
    }
    for (int i = (sum + 1) / 2; i <= sum; i++) {
        if (dp[i]) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}

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

int n, a[100000], r[100000], d[100000];
vector<int> g[100000];

int dfs(int v, int p) {
	int s = 1;
	for (int nv : g[v]) {
		if (nv == p)
			continue;
		r[nv] = v;
		d[nv] = d[v] + 1;
		s += dfs(nv, v);
	}
	a[v] = s;
	return s;
}

int main() {
	cin >> n;
	for (int i = 0, a, b; i < n - 1; ++i) {
		cin >> a >> b;
		--a;
		--b;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}

	dfs(0, 0);

	int x = n - 1;
	for (int i = 0; i < (d[n - 1] - 1) / 2; ++i)
		x = r[x];
	int k = n - a[x];

	cout << (k > n / 2 ? "Fennec" : "Snuke") << endl;
}


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


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

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

int main() {
    int d;
    cin >> d;
    vec c(26);
    rep(i, 26) cin >> c[i];
    int s[365][26] = {};
    rep(i, d) rep(j, 26) cin >> s[i][j];
    int last[365][26] = {};

    vec t(d);
    lint now = 0;

    rep(i, d) {
        lint mx = 0;
        int selected = -1;
        rep(j, 26) {
            lint nw2 = now;

            nw2 += s[i][j];

            int tmp = last[i][j];
            last[i][j] = i+1;
            rep(k, 26) {
                nw2 -= c[k] * (i+1 - last[i][k]);
            }
            last[i][j] = tmp;

            if (nw2 > mx) {
                mx = nw2;
                selected = j;
                t[i] = j;
            }
        }
        for (int j = i; j < d; j++) last[j][selected] = i+1;
    }

    rep(i, d) cout << t[i]+1 << endl;
    return 0;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int const INF = 1001001001;


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

int x,a;
cin >> x >> a;

cout << (x<a? "0":"10") << endl;


return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define ll long long
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
const int N = 3100;
int n,a,b,pa[N],pb[N];
int nex[N << 1],id[N << 1];
string s,f[N << 1];
int main()
{
	n = read(); cin >> s; s = " " + s;
	for(int i = 1;i <= (n << 1);i ++)
	{
		if(s[i] == 'a') pa[id[i] = ++ a] = i;
		else pb[id[i] = ++ b] = i;
	}
	pa[n + 1] = pb[n + 1] = n * 2 + 1, id[n * 2 + 1] = n + 1;
	for(int i = 1,j = 0;i <= n + 1;i ++) while(j < min(pa[i],pb[i])) nex[++ j] = i;
	for(int i = n,j;i >= 1;i --)
	{
		if(pa[i] > pb[i])
		{
			j = pb[i];
			while(pb[id[j]] < pa[id[j]] && (id[j] <= i || pb[id[j]] < pa[id[j] - 1])) {if(id[j] >= i) f[i] += s[j]; j ++;}
			f[i] += f[id[j]];
		}
		else f[i] = "ab" + f[nex[pb[i]]];
		f[i] = max(f[i],f[i + 1]);
	}
	cout << f[1] << "\n";
}

Measured memory_bytes: 14720
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
#define rep(i,j,n) for(int i=(j);i<=((int)n);++i)
#define rev(i,n,j) for(int i=(n);i>=((int)j);--i)
typedef long long int ll;
#define int long long int
const ll INFL=0x3f3f3f3f3f3f3f3fLL;
const int INF=0x3f3f3f3f;
const int mod=1000000007;
#define endl "\n"
#define mem(a,val) memset(a,val,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define pb push_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define readmat(a, n, m) int a[n + 5][m + 5] = {}; rep(i, 1, n) {rep(j, 1, m) cin >> a[i][j];}
#define printmat(a, n, m) rep (i, 1, n) {rep (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define printarr(a, n) rep(i, 1, n) cout << a[i] << " "; cout << endl;
typedef std::map< int,int> mii;
typedef std::vector< int > vi;
typedef std::vector< vi > vvi;
typedef std::pair< int,int > ii;
using namespace std;
#define cerr cout
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);}
const int N = 1e7+5;
const int M = 1e7+1;

int sieve[N];

void go()
{
	rep(i,1,M)
	sieve[i]=1;

	for(int i = 2; i <=M; ++i) 
	{
		if (sieve[i]!=1)
			continue;
		for (int j=2*i;j<=M;j+=i)
		{
			int c=0;
			int r=j;
			while(r>0) 
			{
				if (r%i!=0)
					break;
				c++;
				r/=i;
			}
			sieve[j]*=(1+c);
		}
	}
}

void solve()
{
	go();
	for(int i = 2; i <=N; ++i) 
	{
		if (sieve[i]==1)
			sieve[i]=2;
	}

	int n;
	cin>>n;
	int ans=0;
	for(int i = 1; i <=n; ++i) 
	{
		ans=(ans+sieve[i]*i);
	}
	cout<<ans<<endl;

  

}



signed main()
{
  FAST;
#ifdef LOCAL
    freopen("C:\\Users\\hp\\Documents\\input.txt", "r", stdin);
    freopen("C:\\Users\\hp\\Documents\\output.txt", "w", stdout);
    std::chrono::time_point<std::chrono::high_resolution_clock> start, end;
    start = std::chrono::high_resolution_clock::now();
#endif

solve();

#ifdef LOCAL
    end = std::chrono::high_resolution_clock::now();
    ll elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
    cout<<endl;
    cout << "\nElapsed Time: " << elapsed_time << "ms\n";
#endif

return 0;

}

// vector string set map first second continue break return upper_bound lower_bound length void sort
// stack queue pop size erase empty insert
// #Hala BBCF



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

int main () {;
	int a, b;
	cin >> a >> b;
	
	if(a < b) {
		cout << "a < b" << endl;
	}else if (a > b){
		cout << "a > b" << endl;
	}else{
		cout << "a == b" << endl;
	}
	return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N;
  cin>>N;
  vector<P> A(N);
  cin>>A;

  sort(A.begin(), A.end(), [&](auto a, auto b){
      if(a.second != b.second) return a.second < b.second;
      return a.first < b.first;
    });

  Int ans = 0;
  for(auto p:A) Max<Int>(ans, p.second - p.first + 1);
  multiset<Int> L1, R1;
  multiset<Int> L2, R2;
  for(auto p:A){
    Int l, r; tie(l, r) = p;
    L2.insert(l);
    R2.insert(r);
  }

  for(Int i=0;i<N;i++){
    Int l, r; tie(l, r) = A[i];
    L2.erase(L2.find(l));
    R2.erase(R2.find(r));

    Int a = l;
    Int b = r;
    Int x = *(--L2.end());
    Int y = *R2.begin();
    Int len1 = max<Int>(0, b - a + 1);
    Int len2 = max<Int>(0, y - x + 1);
    Int len = len1 + len2;
    Max(ans, len);

    L2.insert(l);
    R2.insert(r);

  }


  for(Int i=0;i<N-1;i++){
    Int l, r; tie(l, r) = A[i];
    L2.erase(L2.find(l));
    R2.erase(R2.find(r));
    L1.insert(l);
    R1.insert(r);

    Int a = *(--L1.end());
    Int b = *R1.begin();
    Int x = *(--L2.end());
    Int y = *R2.begin();
    Int len1 = max<Int>(0, b - a + 1);
    Int len2 = max<Int>(0, y - x + 1);
    Int len = len1 + len2;
    Max(ans, len);
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 11264
#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>;
using vec_int = vector<int>;
using vec_str = vector<string>;
#define INF (1<<29)

int main()
{
    int N = 0;
    int M = 0;
    string S;
#if 1
	cin >> N;
	cin >> M;
#endif
#if 0
	cin >> S;
#endif
#if 1
    int all_A = 0;
    //vec_str v(N);
    vec_int v(N);
    rep(i, N) {
        cin >> v[i];
        all_A += v[i];
    }
#endif

#if 0
    p pp = make_pair(1, 2);
    //cout << pp.first << endl;
    //cout << pp.second << endl;
#endif

    int ans = 0;
        
    rep(i, N) {
        int a = v[i];
        if( ( a * 4 * M ) >=  all_A ) ans++;
        //cout << v[i] << endl;
        
        if( ans == M ) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
while True:
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        break
    width = ''
    for j in range(h):
        if j == 0 or j == h - 1:
            for i in range(w):
                width += '#'
        else:
            for i in range(w):
                if i == 0 or i == w - 1:
                    width += '#'
                else:
                    width += '.'
        print(width)
        width = ''
    print('')


Measured memory_bytes: 5608
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0

for i in range(a + 1):
  for l in range(b + 1):
    for n in range(c + 1):
      tmp = (500 * i) + (100 * l) + (50 * n)
      if tmp == x:
        ans += 1
        
print(ans)

Measured memory_bytes: 3064
S=input()
T=input()
a=[None]*26
b=[None]*26
k=1
for i in range(26):
    for j in range(len(S)):
        if S[j]==chr(97+i):
            if a[i]==None:
                a[i]=T[j]
            else:
                if T[j]!=a[i]:
                    k=0
                    break
for i in range(26):
    for j in range(len(S)):
        if T[j]==chr(97+i):
            if b[i]==None:
                b[i]=S[j]
            else:
                if S[j]!=b[i]:
                    k=0
                    break
if k==1:print("Yes")
else:print("No")  

Measured memory_bytes: 42556
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define maxn 300010
using namespace std;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while   (ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int w,h,n;
struct P{
    int x,y;
}p[maxn];
bool cmp(P a,P b)
{
    return a.x<b.x;
}
int top1,top2;
struct Segment_Tree{
    int t[maxn*4];
    int tag[maxn*4];
    void build(int k,int l,int r)
    {
        t[k]=tag[k]=0;
        if(l==r)  return;
        int mid=(l+r)/2;
        build(k*2,l,mid);
        build(k*2+1,mid+1,r);
    }
    void update(int k)
    {
        t[k]=max(t[k*2],t[k*2+1]);
    }
    void pushdown(int k)
    {
        if(!tag[k])  return;
        t[k*2]+=tag[k];tag[k*2]+=tag[k];
        t[k*2+1]+=tag[k];tag[k*2+1]+=tag[k];
        tag[k]=0;
    }
    void modi(int k,int l,int r,int x,int y,int z)
    {
        if(l>=x&&r<=y)
        {
            t[k]+=z;
            tag[k]+=z;
            return;
        }
        pushdown(k);
        int mid=(l+r)/2;
        if(mid>=x) modi(k*2,l,mid,x,y,z);
        if(mid<y)  modi(k*2+1,mid+1,r,x,y,z);
        update(k);
    }
}S;
struct X{
    int id,val;
}s1[maxn],s2[maxn];
int ans;
void solve()
{
    sort(p+1,p+n+1,cmp);
    S.build(1,1,n);
    top1=top2=0;
    for(int i=1;i<=n;i++)
    {
        int las=i-1;
        if(p[i].y<=h/2)
        {
            while(top1&&s1[top1].val<p[i].y)
            {
                S.modi(1,1,n,s1[top1].id,las,s1[top1].val-p[i].y);
                las=s1[top1].id-1;
                top1--;
            }
            if(las!=i-1)  s1[++top1]=(X){las+1,p[i].y};
        }
        else{
            while(top2&&s2[top2].val>p[i].y)
            {
                S.modi(1,1,n,s2[top2].id,las,p[i].y-s2[top2].val);
                las=s2[top2].id-1;
                top2--;
            }
            if(las!=i-1)  s2[++top2]=(X){las+1,p[i].y};
        }
        s1[++top1]=(X){i,0};
        s2[++top2]=(X){i,h};
        S.modi(1,1,n,i,i,h-p[i].x);
        ans=max(ans,S.t[1]+p[i+1].x);
    }
}
int main()
{
    w=read();h=read();n=read();
    for(int i=1;i<=n;i++)  p[i].x=read(),p[i].y=read();
    p[++n]=(P){0,0};p[++n]=(P){w,h};
    solve();
    for(int i=1;i<=n;i++)  swap(p[i].x,p[i].y);
    swap(w,h);
    solve();
    printf("%d\n",ans*2);
    return 0;
}

Measured memory_bytes: 15616
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll h,w,n;
    cin>>h>>w>>n;
    ll y,x;
    string s,t;
    cin>>x>>y>>s>>t;
    ll L = 0, R = w + 1, U = 0, D = h + 1;
    for(int i = n - 1; i >= 0; i--) {
        if(t[i] == 'L' && R <= w) R++;
        if(t[i] == 'R' && 1 <= L) L--;
        if(t[i] == 'U' && D <= h) D++;
        if(t[i] == 'D' && 1 <= U) U--;
        if(s[i] == 'L') L++;
        if(s[i] == 'R') R--;
        if(s[i] == 'U') U++;
        if(s[i] == 'D') D--;
        if(w <= L || R <= 1 || h <= U || D <= 1) {
            cout << "NO\n";
            return 0;
        }
    }
 
    cout << (L < y && y < R && U < x && x < D ? "YES\n" : "NO\n");

    return 0;
}


Measured memory_bytes: 920
#include<stdio.h>
#define MAX_HEAP_SIZE 500000
int heap[MAX_HEAP_SIZE + 1];

int hsize = 0;

int left(int id);

int right(int id);

void maxHeapify(int rootId);
void buildMaxHeap(void);

int main(){
  int n;

  scanf("%d", &n);
  for(int i = 1; i <= n; i++){
    scanf("%d", &heap[i]);
    hsize++;
  }

  buildMaxHeap();
  
  for(int i = 1; i <= n; i++){
    printf(" %d", heap[i]);
  }
  printf("\n");
  
  return 0;
}

int left(int id){
  return 2*id;
}

int right(int id){
  return 2*id + 1;
}

void maxHeapify(int rootId){
  int l = left(rootId);
  int r = right(rootId);
  int largest;
  
  //左の子、自分、右の子で値が最大のノードを選ぶ
  if(l <= hsize && heap[l] > heap[rootId]){
    largest = l;
  }
  else {
    largest = rootId;
  }

  if(r <= hsize && heap[r] > heap[largest]){
    largest = r;
  }

  int tmp;
  if(largest != rootId){ //rootIdの子の方が値が大きいとき
    tmp = heap[rootId];
    heap[rootId] = heap[largest];
    heap[largest] = tmp;
    maxHeapify(largest);
  }
}

void buildMaxHeap(){
  for(int i = hsize/2 ; i >= 1; i--){
    maxHeapify(i);
  }
}
    



Measured memory_bytes: 3736
const main = ()=>{
  let [a,b,c,d] = t.s().split('')
  t.o(a==b&&b==c||b==c&&c==d?'Yes':'No')
}
const t = {
  // 入力
  input: require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/),
  // number型取得
  n: (arg:number = 0):any => {
    if(arg) {
      const a:number[]=[];
      for(let i = 0;i < arg; i++) {
        a.push(t.n());
      }
      return a;
    } else {
      const a = t.input[0];
      t.input.shift();
      return Number(a);
    }
  },
  // string型取得
  s: (arg:number = 0):any => {
    if(arg) {
      const a:string[]=[];
      for(let i = 0;i < arg; i++) {
        a.push(t.s());
      }
      return a;
    } else {
      const a = t.input[0];
      t.input.shift();
      return String(a);
    }
  },
  // char型取得
  c: (arg:number = 0):any => {
    if(arg) {
      const a:string[]=[];
      for(let i = 0;i < arg; i++) {
        a.push(t.c());
      }
      return a;
    } else {
      let a = t.input[0].split('');
      const b = a[0];
      a.shift();
      if (a.length > 0) {
        t.input[0] = a.join('');
      } else {
        t.input.shift();
      }
      return String(b);
    }
  },
  o: (...arg)=>{
    console.log(...arg);
  },
  abs: (a)=>{
    return Math.abs(a);
  },
  min: (a)=>{
    return Math.min(a);
  },
  max: (a)=>{
    return Math.max(a);
  },
  floor: (a)=>{
    return Math.floor(a);
  },
  asc: (ar:number[]) => {
    return ar.sort((a,b)=>{return a-b});
  },
  desc: (ar:number[]) => { 
    return ar.sort((a,b)=>{return b-a});
  },
  sw: (a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{
    for(let i=0;i<arr.length;i+=2){
        if(eval(a+op+arr[i]))return arr[i+1]
    }
    return arr[arr.length-1];
  }
}
main()

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

typedef long long lint;
typedef unsigned long long ulint;
const int MOD=1000000007;

int main(){
    const int E='E',W='W';
    int N;
    string s;
    cin >> N >> s;

    int countE[300002];
    countE[0]=0;
    for(int i=0;i<N;i++){
        if(s[i]=='E') countE[i+1]=countE[i]+1;
        else countE[i+1]=countE[i];
    } 
    countE[N+1]=countE[N];

    int mi=300002;
    for(int i=1;i<=N;i++){
        int c=(i-1)-countE[i-1]+countE[N]-countE[i];
        mi=min(mi,c);
    }

    cout << mi << endl;

    return 0;
}

Measured memory_bytes: 1796
import bisect
def bisect_rev(a, x):
    lo = 0
    hi = len(a)
    while lo < hi:
        mid = (lo + hi) // 2
        if x > a[mid]:
            hi = mid
        else:
            lo = mid + 1
    return lo

def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    t = []
    for a in A:
        k = bisect_rev(t, a)
        if k == len(t):
            t.append(a)
        else:
            t[k] = a
    return len(t)

print(main())


Measured memory_bytes: 7832