akhauriyash/Code-Regression huggingface dataset:
#ABC129D-Lamp.py

#import list
import sys
import numpy as np

#main function
def main():
    buffer = sys.stdin.buffer
    H, W = list(map(int,buffer.readline().split()))
    S = np.frombuffer(buffer.read(H*(W+1)), dtype="B") == ord(".")
    S = S.reshape((H,W+1))[:,:-1]
    L = np.empty((H,W), dtype="i4")
    R = np.empty((H,W), dtype="i4")
    U = np.empty((H,W), dtype="i4")
    D = np.empty((H,W), dtype="i4")

    L[:,0] = S[:,0]
    for i in range(1,W):
        L[:,i] = (L[:,i-1] + 1) * S[:,i]

    R[:,-1] = S[:,-1]
    for i in range(1,W):
        R[:,-1-i] = (R[:,-i] + 1) * S[:,-1-i]

    U[0] = S[0]
    for i in range(1,H):
        U[i] = (U[i-1] + 1) * S[i]

    D[-1] = S[-1]
    for i in range(1,H):
        D[-1-i] = (D[-i] + 1) * S[-1-i]

    score = L + R + U + D - 3
    print(int(score.max()))


if __name__ == "__main__":
    main()


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


Measured memory_bytes: 2044
k = int(input())
base = k//50
ans = [i for i in range(base,base+51)]
for i in range(k%50):
    ans[i] += 50
    for j in range(50):
        if i!=j:
            ans[j] -= 1
print(50)
for i in range(50):
    print(ans[i],end=' ')
print()

Measured memory_bytes: 38512
#include <iostream>

using namespace std;

int main() {
  long long K, A, B;
  cin >> K >> A >> B;
  if (B - A < 3) cout << 1 + K << endl;
  else {
    if (A + 1 > K) cout << 1 + K << endl;
    else {
      long long result = 0;
      result += B;
      K -= A + 1;
      while (K > 0) {
        result -= A;
        result += B;
        K -= 2;
      }
      if (K < 0) {
        result -= B;
        result += A;
        result += 1;
      }
      cout << result << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX_N 100010
const int INF = 1e9;
int n;
int dp[MAX_N];

int main() {
    cin >> n;
    for (int i = 0; i < MAX_N; i++) dp[i] = INF;
    
    dp[0] = 0;
    for (int i = 0; i <= n; i++) {
        dp[i + 1] = min(dp[i + 1], dp[i] + 1);
        for (int j = 6; i + j <= n; j*=6) dp[i + j] = min(dp[i + j], dp[i] + 1);
        for (int k = 9; i + k <= n; k*=9) dp[i + k] = min(dp[i + k], dp[i] + 1);
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 640
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

// End of template.


int main(){
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k, q;
    int a[100100];
    cin >> n >> k >> q;
    rep(i, q) { cin >> a[i]; a[i]--; }

    int score[100100];
    fill(begin(score), begin(score) + n, 0);

    rep(ai, q) {
        score[a[ai]] += 1;
    }

    rep(si, n) 
        if (score[si] > q - k)
            print("Yes");
        else
            print("No");

    return 0;
}



Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (a > b) {
            int z;
            z = a; a = b; b = z;
        } if (b > c) {
            int y;
            y = b; b = c; c = y;
        } if (b < a) {
            int x;
            x = b; b = a; a = x;
        }
        System.out.println(a + " " + b + " " + c);
    }
}


Measured memory_bytes: 26232
n = int(input())
a = list(map(int,input().split()))
tf = True
for i in a:
    if i%2 ==0:
        if i % 3 ==0:
            pass
        elif i % 5 == 0:
            pass
        else:
            tf = False
if tf:
    print('APPROVED')
else:
    print('DENIED')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
typedef long long llong;
typedef long double ldouble;
 
using Graph = vector<vector<int>>;
 
// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }
 
// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;
 
//   return gcd(mi, ma%mi);
// }
int main(){
  int R;
  cin >> R;
  cout << 2 * 3.14159265 * R << endl;
}

Measured memory_bytes: 3784
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"

using namespace std;
typedef long long ll;

int main()
{
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  cout << (s < t ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
 
int isPrime(int);
 
int main()
{
  int a[10000],i,n,c=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    if(isPrime(a[i])==1)c++;
  }
 printf("%d\n",c);
 return 0;
}
     
int isPrime(int x){
  int i;
  if(x==2)return 1;
  if(x<2||x%2==0)return 0;
  i=3;
  while(i<=sqrt(x)){
    if(x%i==0)return 0;
    i=i+2;
  }
  return 1;
}


Measured memory_bytes: 2048
require 'pp'

def gets; ARGF.gets; end

class Solver

  def main
    n = gets.chomp.to_i
    s = gets.chomp

    ans = 0
    lc = ''
    0.upto(n-1) do |i|
      if lc != s[i]
        ans += 1
        lc = s[i]
      end
    end

    puts ans
  end
end

if __FILE__ == $0
  Solver.new.main
end


Measured memory_bytes: 2556
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
long double const pi = std::acos(-1.0L);
typedef pair<int,int> P;
const int INF = 1001001001;


int main() {
  int n; cin >> n;
  map<int,int> mp;
  ll sum = 0;
  rep(i,n){
    int a;
    cin >> a;
    mp[a]++;
    sum += a;
  }
  int q; cin >> q;
  rep(i,q){
    int b, c; cin >> b >> c;
    if(mp.count(b)){
      sum += (c-b)*(mp.at(b));
      mp[c]+=mp.at(b);
      mp.erase(b);
      cout << sum << endl;
    }
    else cout << sum << endl;
  }
  
  return 0;
}


Measured memory_bytes: 6516
#include <stdio.h>

#define Mod 1000000007

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

long long combination(long long n, long long k)
{
	long long i, x, y;
	for (i = n, x = 1; i >= n - k + 1; i--) x = x * i % Mod;
	for (i = 2, y = 1; i <= k; i++) y = y * i % Mod;
	return div_mod(x, y, Mod);
}

int main()
{
	int n, i, k;
	long long ans, fact[200001];
	scanf("%d %d", &n, &k);
	if (k > n - 1) printf("%lld\n", combination(n * 2 - 1, n - 1));
	else {
		for (i = 1, fact[0] = 1; i <= n; i++) fact[i] = fact[i-1] * i % Mod;
		for (i = 0, ans = 0; i <= k; i++) ans = (ans + div_mod(fact[n] * fact[n-1] % Mod, ((fact[i] * fact[i] % Mod) * fact[n-i] % Mod) * fact[n-i-1] % Mod, Mod)) % Mod;
		printf("%lld\n", ans);
	}
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 3280
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#define	MOD  1000000007;
#define PI = 3.14159265358979323846;
using namespace std;

int pow(int a, int b)
{
	if (b == 0) {
		return 1;
	}
	if (b % 2 == 0)
	{
		return pow(a*a, b / 2);
	}
	else {
		return pow(a*a, b / 2) * a;
	}

	return 0;
}

int main()
{
	long long N;
	cin >> N;
	long long a[100000];
	set<long long>s;

	for (long long i = 1; i * i <= N; i++)
	{
		if (N % i == 0)
		{
			s.insert(i);
			s.insert(N / i);
		}
	}
	vector<int> v(s.begin(), s.end());
	int d = v.size() / 2;

	int C = 0;
	if (v.size() == 1)
	{
		C = 1;
	}
	else
	{
		C = v[d];
	}
	int digits = 0;
	while (true)
	{
		C /= 10;
		digits++;
		if (C == 0)
		{
			break;
		}
	}
	cout << digits << endl;
}

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

int main() {
  string str;
  cin >> str;
  int a,b,c;
  a = 0;
  b = 0;
  c = 0;

  for(int i = 1 ; i < 4; i++){
    if(str.at(0) == str.at(i)){
         a = a + 1;
    }
  }
    
  for(int i = 2 ; i < 4; i++){
    if(str.at(1) == str.at(i)){
         b = b + 1;
    }
  }
  
  for(int i = 3 ; i < 4; i++){
    if(str.at(2) == str.at(i)){
         c = c + 1;
    }
  }
    
  if(a == 1 && b + c == 1){
         cout << "Yes" << endl;
    }else{
         cout << "No" << endl;
     }
    
}

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

a.sort()

b = []
cnt = 0
for i in range(n):
    for j in range(i+1,n):
        b.append(int(str(a[i])+str(a[j])))
        b.append(int(str(a[j])+str(a[i])))
        cnt += 1
        if cnt > n:
            break

b.sort()

print(b[2])


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

using namespace std;

long long func(int W[], int V[], int n, int w)
{
  long long dp[n + 1][w + 1];
  memset(dp, 0, sizeof(dp));
  
  for (auto i = 1; i <= n; i++) {
    for (auto j = 1; j <= w; j++) {
      if (j >= W[i - 1]) {
        dp[i][j] = max(V[i - 1] + dp[i - 1][j - W[i - 1]], dp[i - 1][j]);
      } else {
        dp[i][j] = dp[i - 1][j];
      }
    }
  }
                                            
  return dp[n][w];
}

int main()
{
  int n, w;
  cin >> n >> w;
  
  int W[n], V[n];
  for (auto i = 0; i < n; i++) {
    cin >> W[i] >> V[i];
  }
  
  cout << func(W, V, n, w) << endl;
  
  return 0;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(), (a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(), (a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl; 
int main(){
    int a,b;
    cin>>a>>b;
    string s;
    cin>>s;
    bool ans = true;
    rep(i,a+b+1){
        //cout<<s[i]-'0'<<endl;
        if(i==a){
            if(s[i]!='-'){
                ans = false;
            }
        }
        else{
            if(s[i]-'0'<0 || s[i]-'0'>9){
                ans = false;
            }
        }
    }
    /*
    if(ans){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    */
   YN(ans);
}

Measured memory_bytes: 256
N = int(input())

MARCH = [0,0,0,0,0]

for i in range (0, N):
	S = str(input())
	if S[0] == 'M':
		MARCH[0]+=1
	if S[0] == 'A':
		MARCH[1]+=1
	if S[0] == 'R':
		MARCH[2]+=1
	if S[0] == 'C':
		MARCH[3]+=1
	if S[0] == 'H':
		MARCH[4]+=1
        
import itertools as it
mokou = list(it.product([0,1], repeat = 5))
count = 0

for i in range (0, len(mokou)):
	if sum(mokou[i]) == 3:
		zen = 1
		for j in range (0, 5):
			if mokou[i][j] == 1:
				zen=zen*MARCH[j]
		count+=zen
        
print(count)

Measured memory_bytes: 9260
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  int N;
  cin >> N;
  map<ll, int> mps;
  vector<ll> A(N);
  REP(i, N) {
    int a;
    cin >> a;
    A[i] = a;
    mps[a]++;
  }
  sort(A.begin(), A.end());
  A.erase(std::unique(A.begin(), A.end()), A.end());
  ll v1 = -1;
  for (int i = A.size() - 1; i >= 0; i--) {
    if(1<mps[A[i]]){
      if(v1==-1&&3<mps[A[i]]){
        cout << A[i] * A[i] << endl;
        return 0;
      }
      if(v1!=-1){
        cout << A[i] * v1 << endl;
        return 0;
      }else{
        v1 = A[i];
      }
    }
  }
  cout << 0 << endl;
}

Measured memory_bytes: 7296
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			int k = sc.nextInt();
			int m = sc.nextInt();
			int size = n;
			if (n == 0 && k == 0 && m == 0)
				break;
			List<Integer> list = new LinkedList<Integer>();
			for (int i = 0; i < n; i++) {
				list.add(i + 1);
			}
			int current = m - 2;
			list.remove(current + 1);
			size--;
			for (int i = 0; i < n - 2; i++) {
				int x = (current + k) % size;
				current = x == 0 ? size - 2 : x - 1;
				list.remove(x);
				size--;
			}
			System.out.println(list.get(0));
		}
	}
}

Measured memory_bytes: 43532
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

int main() {
    int N,M;cin>>N>>M;
    vector<vector<int>> g(N,vector<int>());
    rep(i,M) {
        int u,v;cin>>u>>v;
        u--;v--;
        g[u].push_back(v);
    }
    int S,T;cin>>S>>T;
    S--;T--;
    vector<vector<ll>> dist(N,vector<ll>(3,-1));
    queue<P> qu;
    qu.push(P(S,0));
    dist[S][0] = 0;
    while(!qu.empty()) {
        int v = qu.front().first,three = qu.front().second;
        qu.pop();
        for(auto nxt: g[v]) {
            if(dist[nxt][(three+1)%3] == -1) {
                dist[nxt][(three+1)%3] = dist[v][three] + 1;
                qu.push(P(nxt,(three+1)%3));
            }
        }
    }
    if(dist[T][0] == -1) {
        cout<<-1<<endl;
    } else {
        cout<<dist[T][0]/3<<endl;
    }
}

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


int main(){
    int h , w;
    cin >> h >> w;
    string s[h];
    rep(i , h) cin >> s[i];
    const int dx[]={0,1, 0,-1,1, 1,-1,-1};
    const int dy[]={1,0,-1, 0,1,-1,-1, 1};
    rep(i ,h){
        rep(j , w){
            int cnt=0;
            if(s[i][j]=='#') continue;
            for(int k=0;k<8;++k){
                int ix = j + dx[k];
                int iy = i + dy[k];
                if( ix<0 || ix>=w) continue;
                if( iy<0 || iy>=h) continue;
                if(s[iy][ix]=='#') ++cnt;
            }
            s[i][j] = char('0' + cnt);
            cnt=0;
        }
    }
    rep(i , h) cout << s[i] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

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

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

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

ll ans = 0;
int H, W;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
bool bseen[410][410];
bool seen[410][410];
vector<string> field;

ll black = 0, white = 0;
void dfs(ll h, ll w)
{
    seen[h][w] = true;

    for (ll dir = 0; dir < 4; dir++)
    {
        ll nh = h + dx[dir];
        ll nw = w + dy[dir];

        if (nh < 0 || nw < 0 || nh >= H || nw >= W)
        {
            continue;
        }
        if (seen[nh][nw])
            continue;
        if (field[h][w] == '#')
        {
            if (field[nh][nw] == '#')
                continue;
            white++;
        }
        else
        {
            if (field[nh][nw] == '.')
                continue;
            black++;
        }
        dfs(nh, nw);
    }
}

int main()
{
    cin >> H >> W;
    field.resize(H);

    for (int i = 0; i < H; i++)
    {
        std::cin >> field[i];
    }
    memset(seen, 0, sizeof(seen));

    ll ans = 0;
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            black = 1;
            white = 0;
            if (field[i][j] == '#')
            {
                if (seen[i][j])
                    continue;

                dfs(i, j);
            }
            ans += black * white;
        }
    }
    cout << ans << endl;
    return 0;
}


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

signed main() 
{
	int n;
    cin >> n;
    string res = "";
    while(n!=0)
        res = (char)('a'+((n-n/26*26+25)%26)) + res , n = (n-((n-n/26*26+25)%26)+1)/26;
    cout << res << endl;
}

Measured memory_bytes: 3596
package main

import "fmt"

func main() {
	var line string
	fmt.Scan(&line)

	y := 0
	for i := range make([]struct{}, 4) {
		y *= 10
		y += int(line[i] - '0')
	}

	m := 0
	for i := range make([]struct{}, 2) {
		m *= 10
		m += int(line[i+5] - '0')
	}

	ans := "Heisei"
	if y == 2019 && m > 4 || y > 2019 {
		ans = "TBD"
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<cstdio>
using ull = unsigned long long;

int main(){
	int K;
	scanf("%d", &K);
	ull lunlun[K+10];
	for (int i = 1; i <= 9; ++i){
		lunlun[i] = i;
	}
	int id_upper_digits = 1, last = 9;
	while(last < K){
		ull upper_digits = lunlun[id_upper_digits];
		ull repeat_last_digit = upper_digits*10 + upper_digits%10;
		if(upper_digits%10 == 0){
			lunlun[last+1] = repeat_last_digit;
			lunlun[last+2] = repeat_last_digit + 1;
			last += 2;
		}else if(upper_digits % 10 == 9){
			lunlun[last+1] = repeat_last_digit - 1;
			lunlun[last+2] = repeat_last_digit;			
			last += 2;
		}else{
			lunlun[last+1] = repeat_last_digit - 1;
			lunlun[last+2] = repeat_last_digit;
			lunlun[last+3] = repeat_last_digit + 1;
			last += 3;
		}
		id_upper_digits++;
	}
	printf("%llu\n", lunlun[K]);
	return 0;
}

Measured memory_bytes: 2460
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;

int n,m;
long long x[1111], y[1111], z[1111];
long long mem[1111][1111][11];

long long nx[] = { 1,-1, 1,-1, 1,-1, 1,-1};
long long ny[] = { 1, 1,-1,-1, 1, 1,-1,-1};
long long nz[] = { 1, 1, 1, 1,-1,-1,-1,-1};

long long slv(int now, int cnt, int f);

int main(){
  ios_base::sync_with_stdio(false);

  for(int i=0;i<1111;i++){
    for(int j=0;j<1111;j++){
      for(int k=0;k<8;k++){
        mem[i][j][k] = -1;
      }
    }
  }

  cin >> n >> m;
  for(int i=0;i<n;i++){
    cin >> x[i] >> y[i] >> z[i];
  }

  long long ans = 0;
  for(int i=0;i<8;i++){
    ans = max(ans, slv(0, 0, i));
  } 

  cout << ans << endl;  

  return 0;
}

long long slv(int now, int cnt, int f){
  if(now == n){
    if(cnt != m){
      return (-30000000000 * 1000);
    }
    return 0;
  }
  if(cnt == m){
    return 0;
  }
  if(mem[now][cnt][f] != -1){
    return mem[now][cnt][f];
  }

  long long a = x[now]*nx[f] + y[now]*ny[f] + z[now]*nz[f];

  return mem[now][cnt][f] = max(slv(now+1, cnt, f), slv(now+1, cnt+1, f) + a);
}


Measured memory_bytes: 106368
from bisect import bisect_left

n = int(input())
s = list(input())
q = int(input())
query = [input() for _ in range(q)]

p = [[] for _ in range(26)]

for i, x in enumerate(s):
    p[ord(x) - ord('a')].append(i)

for x in query:
    a, b, c = x.split()
    #print(c)
    if a == '1':
        b = int(b) - 1
        if s[b] == c:
            continue
        d = ord(s[b]) - ord('a')
        e = ord(c) - ord('a')
        temp = bisect_left(p[d], b)
        p[d].pop(temp)
        temp = bisect_left(p[e], b)
        p[e].insert(temp, b)
        s[b] = c
    else:
        b = int(b) - 1
        c = int(c) - 1
        #print(b, c)
        ans = 0
        for i in range(26):
            L = bisect_left(p[i], b)
            if L >= len(p[i]):
                continue
            if p[i][L] <= c:
                ans += 1
        print(ans)

Measured memory_bytes: 32700
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(false);
        cout << setprecision(15) << fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N;
    cin >> N;
    int ans = 0;
    REPF(i, 1, N + 1) {
        if (i % 2 == 0) continue;

        int cnt = 0;
        REPF(j, 1, N + 1) {
            if (i % j == 0) cnt++;
        }
        if (cnt == 8) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}



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

int n,v[1000];
vector<char> ans;
void MINUS(string s){
  v[s[0]]--;v[s[1]]--;
}
void PLUS(string s){
  v[s[0]]++,v[s[1]]++;
}
void F(string s){
  if(v[s[0]]<v[s[1]])v[s[0]]+=2,v[s[1]]-=2,ans.push_back(s[0]);
  else v[s[0]]-=2,v[s[1]]+=2,ans.push_back(s[1]);
}

int main(){
  cin>>n;
  for(int i='A';i<='C';i++){
    cin>>v[i];
    v[i]<<=1;
  }
  string now,nxt="AB";cin>>now;
  while(n--){
    if(n)cin>>nxt;
    MINUS(nxt);
    F(now);
    PLUS(nxt);
    now=nxt;
    if(min({v['A'],v['B'],v['C']})<0){cout<<"No"<<endl;return 0;}
  }
  cout<<"Yes"<<endl;
  for(char p:ans)cout<<p<<endl;
}


Measured memory_bytes: 3740
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;
typedef complex<double> Complex;

const double EPS = 1e-10, PI = M_PI;
ll N;
Complex P[10];
double L[10];

bool check(Complex p, vector<double> r) {
  bool ret = true;
  REP(i, 0, N) ret = ret && abs(p - P[i]) < r[i] + EPS;
  return ret;
}

bool ok(double h) {
  vector<double> r(N);
  REP(i, 0, N) {
    if(h > L[i]) return false;
    r[i] = sqrt(L[i] * L[i] - h * h);
  }

  REP(i, 0, N) if(check(P[i], r)) return true;

  REP(i, 0, N) REP(j, i + 1, N) {
    Complex p1 = P[i], p2 = P[j];
    double r1 = r[i], r2 = r[j];

    if(abs(p2 - p1) > r1 + r2) continue;
    if(abs(p2 - p1) < abs(r2 - r1)) continue;

    double d = abs(p2 - p1);
    double t = abs((d * d + r1 * r1 - r2 * r2) / (d * 2));
    double h = sqrt(r1 * r1 - t * t);

    Complex u = (p2 - p1) / d;
    Complex v = u * Complex(0, 1);
    Complex q1 = p1 + u * t - v * h;
    Complex q2 = p1 + u * t + v * h;

    if(check(q1, r)) return true;
    if(check(q2, r)) return true;
  }

  return false;
}

int main(void) {
  while(cin >> N, N) {
    REP(i, 0, N) {
      double x, y;
      cin >> x >> y >> L[i];
      P[i] = Complex(x, y);
    }

    double l = 1, h = 1e5;
    REP(_, 0, 100) {
      double m = (l + h) / 2;
      if(ok(m)) l = m; else h = m;
    }
    printf("%.15lf\n", l);
  }
}


Measured memory_bytes: 3348
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN = 500005;
int n, Q, d[MAXN];
long long A[MAXN], B[MAXN];

int main() {
	scanf("%d%lld", &n, &A[0]);
	for(int i = 1; i <= n; ++i) {
		scanf("%d", d + i);
		A[i] = min(A[i-1], abs(A[i-1] - d[i]));
	}
	
	B[n] = 1;
	for(int i = n; i--; )
		if(B[i+1] <= d[i+1] / 2) B[i] = B[i+1];
		else B[i] = B[i+1] + d[i+1];
	
	scanf("%d", &Q);
	for(int i; Q--; ) {
		scanf("%d", &i);
		puts(A[i-1] >= B[i] ? "YES" : "NO");
	}
	return 0;
}

Measured memory_bytes: 11648
import java.util.Scanner;

/**
 * 大岩達典 J4-170821<br>
 * A-Biscuits<br>
 * https://beta.atcoder.jp/contests/agc017/tasks/agc017_a
 * <br>
 * 教壇から見て左中央<br>
 * <br>
 */
public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		final int n = scanner.nextInt();
		final int p = scanner.nextInt();
		int odd = 0;
		for (int i = 0; i < n; i++) {
			int tmp = scanner.nextInt();
			if (tmp % 2 == 1) odd++;
		}
		scanner.close();
		
		long result;
		if (odd == 0) {
			if (p == 0) result = (long)Math.pow(2, n);
			else result = 0;
		} else {
			result = (long)Math.pow(2, n-1);
		}
		
		System.out.println(result);
	}
	
}


Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <deque>
#include <bits/stdc++.h>
//#include "testlib.h"
using namespace std;
#define ll long long
#define pii pair<int,int>
#define qi ios::sync_with_stdio(0)

bool debug=true;

/*    *************************************
	  * Written in New Computer           *
	  * The following code belongs to     *
	  * XiaoGeNintendo of HellHoleStudios *
	  *************************************
*/
template<typename T1,typename T2>ostream& operator<<(ostream& os,pair<T1,T2> ptt){
	os<<ptt.first<<","<<ptt.second;
	return os;
}
template<typename T>ostream& operator<<(ostream& os,vector<T> vt){
	os<<"{";
	for(int i=0;i<vt.size();i++){
		os<<vt[i]<<" ";
	}
	os<<"}";
	return os;
}

ll x,y;
int main(int argc,char* argv[]){
	cin>>x>>y;
	if(x==1 || y==1){
		cout<<1<<endl;
		return 0;
	}
	cout<<(x*y+1)/2<<endl;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;

//map<string>a
class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint & a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator-=(const mint & a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator*=(const  mint & a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint & a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint & a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint & a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint & a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint & a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream & os, const mint & m) {
		os << m.x;
		return os;
	}
};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
//組み合わせ
void recursive_comb(vector<int> indexes, int s, int rest, std::function<void(vector<int>)> f) {
	if (rest == 0) {
		f(indexes);
	}
	else {
		if (s < 0) return;
		recursive_comb(indexes, s - 1, rest, f);
		indexes[rest - 1] = s;
		recursive_comb(indexes, s - 1, rest - 1, f);
	}
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(vector<int>)> f) {
	vector<int>indexes(k);
	recursive_comb(indexes, n - 1, k, f);
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
int main() {
	int N;
	int K;
	cin >> N >> K;
	vector<double>p(N);
	vector<double>q(N+1,0);
	rep(i, N) {
		cin >> p[i];
		q[i+1] += p[i] + q[i];
		
		
	}
	double ans=0;
	double tmp;
	for (ll i = K; i <=N;i++) {
		tmp = q[i]-q[i-K];
		ans = max(ans, tmp);
	}
	cout << fixed<<setprecision(9) <<((ans+K)/ 2);
}


Measured memory_bytes: 3328
def myAnswer(K:int,S:int) -> int:
   ans = 0
   for x in range(K+1):
      for y in range(K+1):
        z = S - (x + y)
        if 0 <= z and z <= K:
           ans += 1
   return ans

def modelAnswer():
   return
def main():
   K,S = map(int,input().split())
   print(myAnswer(K,S))
if __name__ == '__main__':
   main()

Measured memory_bytes: 3060
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)

typedef long long ll;

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

    ll A, P;
    cin >> A >> P;
    cout << (3 * A + P) / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#define inf 1e9

using namespace std;
typedef pair<int, int> P;

struct edge{
	int to, cost;
	edge(){}
	edge(int a, int b){
		to = a, cost = b;
	}
};

int N, M, S;
int s[20];
int d[105];
int sum[40000];
vector<edge> G[40000];
int dist[40000];

void dijkstra()
{
	for(int i = 0; i < S; i++) dist[i] = inf;
	dist[0] = 0;
	
	priority_queue< P, vector<P>, greater<P> > Q;
	Q.push( make_pair(0, 0) );
	
	int v, d;
	while(Q.size()){
		d = Q.top().first;
		v = Q.top().second;
		Q.pop();
		if(dist[v] < d) continue;
		for(int i = 0; i < G[v].size(); i++){
			if(dist[G[v][i].to] > d + G[v][i].cost){
				dist[G[v][i].to] = d + G[v][i].cost;
				Q.push( make_pair(dist[G[v][i].to], G[v][i].to) );
			}
		}
	}
}

int main(void)
{
	while(1){
		cin >> N >> M;
		if(N == 0 && M == 0) break;
		
		for(int i = 0; i < N; i++) cin >> s[i];
		for(int i = 0; i < M; i++) cin >> d[i];
		sort(d, d+M);
		
		S = 1 << N;
		for(int i = 0; i < S; i++){
			sum[i] = 0;
			for(int j = 0; j < N; j++){
				if(i & (1 << j)) sum[i] += s[j];
			}
		}
		
		for(int i = 0; i < S; i++) G[i].clear();
		for(int i = 0; i < S; i++){
			for(int j = 0; j < N; j++){
				if(i & (1 << j)) continue;
				int cost = 0;
				for(int k = 0; k < M; k++){
					if(d[k] > sum[i] && d[k] < sum[i | (1<<j)]){
						cost += min(d[k] - sum[i], sum[i | (1<<j)] - d[k]);
					}
				}
				G[i].push_back(edge(i | (1<<j), cost));
			}
		}
		
		dijkstra();
		
		int ans = dist[S-1];
		for(int i = 0; i < M; i++){
			if(sum[S-1] < d[i]) ans += d[i] - sum[S-1];
		}
		cout << ans << endl;
	}
	
	return 0;
}


Measured memory_bytes: 7924
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second

int main(){
    int a,b,q;
    cin >>a>>b>>q; 
    vector<ll> s(a),t(b);
    for(int i=0;i < a;i++)
    {
        cin >> s.at(i);
    }
    for(int i=0;i < b;i++)
    {
        cin >> t.at(i);
    }

    for(int i=0;i < q;i++)
    {
        ll x,ls,rs,lt,rt,ans=pow(10,11);
        cin >> x;

        ll left=0,right=a-1;
        while(abs(left-right)>1){
            ll mid=(left+right)/2;
            if(s.at(mid)<x){
                left=mid;
            }else{
                right=mid;
            }
        }
        ls=left;rs=right;

        left=0;
        right=b-1;
        while(abs(left-right)>1){
            ll mid=(left+right)/2;
            if(t.at(mid)<x){
                left=mid;
            }else{
                right=mid;
            }
        }
        lt=left;rt=right;

        ans=min(ans,abs(s.at(ls)-x)+abs(t.at(lt)-s.at(ls)));
        ans=min(ans,abs(t.at(lt)-x)+abs(s.at(ls)-t.at(lt)));
        ans=min(ans,abs(s.at(rs)-x)+abs(t.at(rt)-s.at(rs)));
        ans=min(ans,abs(t.at(rt)-x)+abs(s.at(rs)-t.at(rt)));
        
        ans=min(ans,abs(s.at(ls)-x)+abs(t.at(rt)-s.at(ls)));
        ans=min(ans,abs(s.at(rs)-x)+abs(t.at(lt)-s.at(rs)));
        ans=min(ans,abs(t.at(lt)-x)+abs(s.at(rs)-t.at(lt)));
        ans=min(ans,abs(t.at(rt)-x)+abs(s.at(ls)-t.at(rt)));

        cout << ans << endl;
    }
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;

  int a = 0;

  for (int i = 0; i < N; i++){
    int x;
    cin >> x;

    if ( x > K / 2) {
      a += 2 * (K - x);
    } else {
      a += 2 * x;
    }
  }

  cout << a << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int
main ()
{
  int a, b;
  cin >> a >> b;
  int c = a / b;
  int d = a - c * b;
  double e = static_cast < double >(a) / b;
  printf ("%d %d %lf\n", c, d, e);
}

Measured memory_bytes: 1176
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

#define INF (1<<29)

int main(){
  int time[101][101], cost[101][101];
  int n, m;
  int from, to, Cost, Time;
  
  while(cin >> n >> m){
    if(n == 0 && m == 0) break;
    for(int i = 1 ; i <= m ; i++){
      for(int j = 1 ; j <= m ; j++){
	if(i == j) time[i][j] = cost[i][j] = 0;
	else time[i][j] = cost[i][j] = INF;
      }
    }
    
    while(n--){
      cin >> from >> to >> Cost >> Time;
      cost[from][to] = cost[to][from] = Cost;
      time[from][to] = time[to][from] = Time;
    }
    
    for(int k = 1 ; k <= m ; k++){
      for(int i = 1 ; i <= m ; i++){
	for(int j = 1 ; j <= m ; j++){
	  cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j]);
	  time[i][j] = min(time[i][j], time[i][k]+time[k][j]);
	}
      }
    }
    int num;
    cin >> n;
    while(n--){
      cin >> from >> to >> num;
      if(num == 0) cout << cost[from][to] << endl;
      else cout << time[from][to] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 944
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int a = Integer.parseInt(str[0]);
    int b = Integer.parseInt(str[1]);
    if(a>b && b!=1 || a==1 && b!=1)
      System.out.println("Alice");
    else if(a<b || b==1 && a!=1)
      System.out.println("Bob");
    else
      System.out.println("Draw");
  }
}

Measured memory_bytes: 32728
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <iomanip>
 
using namespace std;
 
mt19937 Rand(16092002);
mt19937_64 BigRand(16092002);
 
typedef long long ll;
 
typedef long long ll;
 
struct edge
{
    int v, to;
    ll cap;
    edge(int a, int b, ll c)
    {
        v = a, to = b, cap = c;
    }
    edge() {}
};
 
const int N = 1e6 + 7;
 
vector <edge> e;
vector <int> g[N];
int us[N];
int usbs = 1;
int d[N];
int q[N];
int ded[N];
int ptr[N];
int after_bfs = 1;
int visb = 1;
ll ans = 0;
int qh, qt;
int s, t;
int l;
 
void add_edge(int u, int v, ll cap)
{
    g[u].push_back(e.size());
    e.push_back({u, v, cap});
    g[v].push_back(e.size());
    e.push_back({v, u, 0});
}
 
bool bfs()
{
    qh = qt = 0;
    us[s] = usbs;
    q[qt++] = s;
    d[s] = 0;
    while (qh < qt)
    {
        int v = q[qh++];
        for (auto c : g[v])
        {
            if (us[e[c].to] != usbs && e[c].cap >= l)
            {
                d[e[c].to] = d[v] + 1;
                us[e[c].to] = usbs;
                q[qt++] = e[c].to;
            }
        }
    }
    return (us[t] == usbs++);
}
 
int dfs(int v = s, ll c = 1e18)
{
    if (!c)
    {
        return 0;
    }
    if (v == t)
    {
        ans += c;
        return c;
    }
    if (ded[v] != after_bfs)
    {
        ded[v] = after_bfs;
        ptr[v] = 0;
    }
    for (; ptr[v] < (int) g[v].size(); ptr[v]++)
    {
        int ind = g[v][ptr[v]];
        if (e[ind].cap >= l && d[e[ind].to] == d[v] + 1)
        {
            ll x = dfs(e[ind].to, min(c, e[ind].cap));
            if (x)
            {
                e[ind].cap -= x;
                e[ind ^ 1].cap += x;
                return x;
            }
        }
    }
    return 0;
}
 
int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
#else
    ///freopen("flow2.in", "r", stdin);
    //freopen("flow2.out", "w", stdout);
#endif
    int n;
    scanf("%d", &n);
    vector <int> a(n + 1);
    ll res = 0;
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
        if (a[i] > 0)
        {
            res += a[i];
        }
    }
    for (int i = 1; i <= n; i++)
    {
        if (a[i] < 0)
        {
            for (int j = i; j <= n; j += i)
            {
                if (a[j] > 0)
                {
                    add_edge(i, j, 1e18);
                }
            }
        }
    }
    s = 0, t = n + 1;
    for (int i = 1; i <= n; i++)
    {
        if (a[i] < 0) add_edge(s, i, -a[i]);
        else add_edge(i, t, a[i]);
    }
    l = (1 << 30);
    for (; l > 0; l /= 2)
    {
        while (bfs())
        {
            after_bfs++;
            while (dfs())
            {
                continue;
            }
        }
    }
    cout << res - ans << '\n';
}


Measured memory_bytes: 33024
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (ll)(v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(o,0,n)cout<<v[o]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define M 100010


int main(){
    IOS;
     
    ll h,w,k;cin>>h>>w>>k;
    char a[h][w];
    rep(i,0,h)rep(j,0,w)cin>>a[i][j];
    ll ct=0;
    rep(i,0,h)rep(j,0,w)if(a[i][j]=='#')ct++;
    ll ans=0;
    rep(i,0,(1<<h))rep(j,0,(1<<w)){
    	ll b[h]={0},c[w]={0};
    	rep(p,0,h)if(i&(1ll<<p))b[p]=1;
    	rep(p,0,w)if(j&(1ll<<p))c[p]=1;
    	ll cnt=ct;
    	rep(i1,0,h)rep(j1,0,w)if((b[i1] or c[j1]) and a[i1][j1]=='#')cnt--;
    	if(cnt==k)ans++;
    }
    cout<<ans;
     
     
     
     
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<db, db> pd;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
typedef vector<vi> vii;
typedef vector<vl> vll;
typedef vector<vd> vdb;
typedef vector<vb> vbb;
typedef vector<vc> vcc;
typedef vector<vs> vss;

#define f first
#define s second	
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(a) (x).rbegin(), (x).readnd()
#define rsz readsize
#define ins insert
#define cnt count
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

#define F0R(i, a, b) for(int i = (a); i < (b); ++i)
#define FOR(i, a) F0R(i, 0, a)
#define R0F(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define ROF(i, a) R0F (i, 0, a)
#define trav(a, x) for (auto& a: x)

const int MOD = 1e9+7;

//input
template<class A> void read(complex<A>& c);
template<class A, class B> void read(pair<A,B>& p);
template<class A> void read(vector<A>& v);
template<class A, size_t SZ> void read(array<A,SZ>& a);

template<class T> void read(T& x) { cin >> x; }
void read(db& d) { str t; read(t); d = stod(t); }
void read(ld& d) { str t; read(t); d = stold(t); }
template<class H, class... T> void read(H& h, T&... t) { read(h); read(t...); }

template<class A> void read(complex<A>& c) { A a,b; read(a,b); c = {a,b}; }
template<class A, class B> void read(pair<A,B>& p) { read(p.f,p.s); }
template<class A> void read(vector<A>& x) { trav(a,x) read(a); }
template<class A, size_t SZ> void read(array<A,SZ>& x) { trav(a,x) read(a); }

//output
template<class A> void print(A x) { cout << (x); }
template<class H, class... T> void print(const H& h, const T&... t) {
	print(h); print(t...); }
void prints() { print("\n"); } // print w/ spaces
template<class H, class... T> void prints(const H& h, const T&... t) {
	print(h); if (sizeof...(t)) print(" "); prints(t...); }

void setIn(str s) {freopen(s.c_str(), "r", stdin);}
void setOut(str s) { freopen(s.c_str(), "w", stdout);}
void unsyncIO() { ios::sync_with_stdio(0); cin.tie(0);}
void setIO(str s= ""){
	unsyncIO();
	if(sz(s)) { setIn(s+".in"), setOut(s+".out");}
}

void solve(){
	int n, ans = 0;
	read(n);
	vi a(n);
	read(a);
	FOR(i, n)
		F0R(j, i+1, n)
			F0R(k, j+1, n)
				if(a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k]&&a[i]+a[j]>a[k]&&a[i]+a[k]>a[j]&&a[j]+a[k]>a[i])
					ans++;
	prints(ans);
}
int main(){
	setIO();
	int t=1;
	//read(t);
	while(t--)
		solve();
	return 0;
}


Measured memory_bytes: 3656
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin >> n;
    long long ans = 1 ;
    for (int i = 1 ; i <= n ;  i ++ ) {
        ans  *= i;
        ans %= 1000000007;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a,b,d,r;
    double f;
    scanf("%d %d",&a,&b);
    d = a/b;
    r = a%b;
    f = 1.0*a/b;
    printf("%d %d %.5f\n",d,r,f);
    return 0;
}


Measured memory_bytes: 2080
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	string S;
	char c1, c2;
	int cnt1 = 1, cnt2 = 0;
	cin >> S;
	bool c2find = false;

	c1 = S[0];
	rep1(i, 1, 3) {
		if (S[i] == c1) cnt1++;
		else if (!c2find) {
			c2 = S[i];
			cnt2++;
			c2find = true;
		}
		else if (S[i] == c2) cnt2++;
	}

	if (cnt1 == 2 && cnt2 == 2) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

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

using namespace std;


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int ans=0;
	while (n > 0) {
		ans <<= 1;
		ans++;
		n >>= 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
# coding: utf-8

LIMIT = 999999

prime = [0, 1] + [0 if i % 2 == 0 else 1 for i in range(3, LIMIT + 1)]

for i in range(3, LIMIT + 1):
    if prime[i - 1]:
        for j in range(i ** 2, LIMIT + 1, i):
            prime[j - 1] = 0

while True:
    try:
        n = int(input())
    except EOFError:
        break

    print(sum(prime[:n]))



Measured memory_bytes: 21236
#!/usr/bin/env python
# coding: utf-8

import sys

def get_answer(params):
    palindrome_count = 0
    for param in params:
        if param == param[::-1]:
            palindrome_count += 1
    return palindrome_count


def main():
    params = [line.rstrip() for line in sys.stdin.readlines()]
    print get_answer(params)

if __name__ == '__main__':
    main()

Measured memory_bytes: 7256