akhauriyash/Code-Regression huggingface dataset:
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

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

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    cout << (180 * (n - 2)) << endl;
    return 0;
}

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

using namespace std;

const int INF = 1 << 29;

struct UnionFind
{
  vector< int > data;

  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }

  int find(int k)
  {
    return (data[k] < 0 ? k : data[k] = find(data[k]));
  }

  void unite(int x, int y)
  {
    x = find(x);
    y = find(y);
    if(x == y) return;
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
  }
};

vector< pair< int, int > > g[100001];
vector< int > leftt[100001], rightt[100001], just[100001];
vector< int > gg[100001];
int deg[100001];


int rec(int idx, int back = -1)
{
  if(back != -1) {
    int tmp = max(leftt[idx][back], rightt[idx][back + 1]);
    if(tmp != INF) return (tmp);
  }
  if(rightt[idx][0] == INF) {
    for(int i = 0; i < g[idx].size(); i++) {
      int to, rev;
      tie(to, rev) = g[idx][i];
      if(i == back) continue;
      just[idx][i] = rec(to, rev) + 1;
    }
    for(int i = 0; i < g[idx].size(); i++) {
      leftt[idx][i + 1] = max(leftt[idx][i], just[idx][i]);
    }
    for(int i = (int) g[idx].size() - 1; i >= 0; i--) {
      rightt[idx][i] = max(rightt[idx][i + 1], just[idx][i]);
    }
  }
  if(back == -1) return (rightt[idx][0]);
  return (max(leftt[idx][back], rightt[idx][back + 1]));
}


int main()
{
  int N, M;
  vector< pair< int, int > > edges, arcs;

  scanf("%d %d", &N, &M);

  UnionFind uf(N);

  for(int i = 0; i < M; i++) {
    int x, y, t;
    cin >> x >> y >> t;
    --x, --y;
    if(t == 1) {
      arcs.emplace_back(x, y);
      g[x].emplace_back(y, -1);
    } else {
      if(uf.find(x) == uf.find(y)) {
        cout << "Infinite" << endl;
        return (0);
      }
      uf.unite(x, y);
      edges.emplace_back(x, y);
      g[y].emplace_back(x, g[x].size());
      g[x].emplace_back(y, g[y].size() - 1);
    }
  }

  {
    for(auto &e : arcs) {
      gg[uf.find(e.first)].push_back(uf.find(e.second));
      ++deg[uf.find(e.second)];
    }
    vector< int > order;
    for(int i = 0; i < N; i++) {
      if(deg[i] == 0) order.push_back(i);
    }
    for(int i = 0; i < order.size(); i++) {
      for(auto &e : gg[order[i]]) {
        if(--deg[e] == 0) order.push_back(e);
      }
    }
    if(order.size() != N) {
      cout << "Infinite" << endl;
      return (0);
    }
  }


  int ret = 0;
  for(int i = 0; i < N; i++) {
    int sz = g[i].size();
    just[i].assign(sz, INF);
    leftt[i].assign(sz + 1, INF);
    rightt[i].assign(sz + 1, INF);
    leftt[i][0] = rightt[i][sz] = 0;
  }
  for(int i = 0; i < N; i++) ret = max(ret, rec(i));
  cout << ret << endl;
}

Measured memory_bytes: 35472
import java.util.*;
 
public class Main {
    public static void main(String args[] ) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        double shakkin = 100000;
        double N = sc.nextInt();
        double totalShakkin = 0;
        
        for (int i=0; i<N; i++){
        	totalShakkin = shakkin + shakkin*0.05;
        	shakkin = totalShakkin;
        	if(shakkin % 1000 > 0){
        		shakkin = (shakkin - shakkin % 1000) + 1000;
        	}
        }
        
        int yamikin = (int)shakkin;
        
        System.out.println(yamikin);
        
    }
}

Measured memory_bytes: 26200
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,n) n = unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;


struct point
{
	long long name; long long dist;
bool operator<(const point& rhs) const {
return dist > rhs.dist;
}
};

ll const MAX = 5005;
vll v[MAX];

ll dist[MAX];
ll fr[MAX];
ll stk[MAX];

ll f(ll start, ll n, ll k) {
	REP(i, 1, n) {
		dist[i] = -1;
		fr[i] = -1;
		stk[i] = 0;
	}
	queue<ll> qu;
	qu.push(start);
	dist[start] = 0;
	REP(i, 0, SIZE(v[start])-1) {
		ll nbd = v[start][i];
		fr[nbd] = nbd;
	}
	ll ans = 1;
	while (!qu.empty()) {
		ll cur = qu.front();
		qu.pop();
		REP(i, 0, SIZE(v[cur]) - 1) {
			ll next = v[cur][i];
			if (dist[next] == -1) {
				dist[next] = dist[cur] + 1;
				if (fr[cur] != -1) {
					fr[next] = fr[cur];
				}
				if (dist[next] <= k / 2) {
					ans++;
					qu.push(next);
				}
				if (dist[next] == k / 2 + 1) {
					stk[fr[next]]++;
					
				}
			}
		}
	}
	ll mos = 0;
	if(k % 2 == 1) {
		REP(i, 1, n) {
			mos = max(mos, stk[i]);
		}
	}
	//cout << start << " " << ans + mos << endl;
	return ans + mos;
}

int main(){
	ll n, k;
	cin >> n >> k;
	REP(i, 1, n - 1) {
		ll a, b;
		cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	ll max_v = -1;
	REP(i, 1, n) {
		ll t = f(i, n,k);
		max_v = max(max_v, t);
	}
	cout << n - max_v << endl;
}

Measured memory_bytes: 512
def get_num(S):
    num = 0
    for i in range(len(S)):
        num = num + S[len(S) - i - 1] * (10**i)
    return num


S = [int(x) for x in str(input())]

min = 10000000
for i in range(len(S) - 2):
    n = get_num(S[i:i+3])
    if min > abs(n - 753):
        min = abs(n - 753)

print(min)


Measured memory_bytes: 3060
from bisect import bisect_left
import sys
input = sys.stdin.readline

N = int(input())
xy = [[int(i) for i in input().split()] for _ in range(N)]
xy.sort()

ylist = [y for _, y in xy]
ylist.sort()
for i in range(N) :
    xy[i] = [i, bisect_left(ylist, xy[i][1])]

MOD = 998244353

def bit_sum(i) :
    s = 0
    while i > 0 :
        s += bit[i]
        i -= i & -i
    return s

def bit_add(i, x) :
    while i <= N :
        bit[i] += x
        i += i & -i

lu = [0] * N
ld = [0] * N
ru = [0] * N
rd = [0] * N

power = [1]
for _ in range(N) :
    power.append(power[-1] * 2 % MOD)

bit = [0] * (N + 1)
for i, (x, y) in enumerate(xy) :
    ld[i] = bit_sum(y+1)
    lu[i] = i - ld[i]
    bit_add(y+1, 1)

bit = [0] * (N + 1)
for i, (x, y) in enumerate(xy[::-1]) :
    rd[N-i-1] = bit_sum(y+1)
    ru[N-i-1] = i - rd[N-i-1]
    bit_add(y+1, 1)

ret = 0
for i in range(N) :
    ret += (power[lu[i]]-1)*power[ld[i]]*power[ru[i]]*(power[rd[i]]-1)
    ret += power[lu[i]]*(power[ld[i]]-1)*(power[ru[i]]-1)*power[rd[i]]
    ret -= (power[lu[i]]-1)*(power[ld[i]]-1)*(power[ru[i]]-1)*(power[rd[i]]-1)
    ret += power[lu[i]] * power[ld[i]] * power[ru[i]] * power[rd[i]]
    ret %= MOD
    
print(ret)

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

void solve(){
	int n, ans = 2, a;
	scanf("%d", &n);
	REP(i, 0, n) {
		scanf("%d", &a);
		if (a & 1) {
			ans = 1;
		}
	}
	if (ans == 1) {
		printf("first\n");
	} else {
		printf("second\n");
	}
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


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


class dice {
public:
	int f[6];
	dice() {}
	void roll(int i, int j, int k, int l) {
		int tmp;
		tmp = f[i];
		f[i] = f[j];
		f[j] = f[k];
		f[k] = f[l];
		f[l] = tmp;
	}
	void roll_z() { roll(1, 2, 4, 3); }
	void roll_y() { roll(0, 2, 5, 3); }
	void roll_x() { roll(0, 1, 5, 4); }

	void move(char ch) {
		if (ch == 'E') {
			for (int i = 0; i < 3; i++) {
				roll_y();
			}
		}
		if (ch == 'W') {
			roll_y();
		}
		if (ch == 'N') {
			roll_x();
		}
		if (ch == 'S') {
			for (int i = 0; i < 3; i++) {
				roll_x();
			}
		}
		
	}
	int top() {
		return f[0];
	}
};



int main() {
	dice d1;
	string com;

	for (int i = 0; i < 6; i++) {
		cin >> d1.f[i];
	}
	cin >> com;
	int N = com.size();

	
	for (int i = 0; i < N; i++) {
		d1.move(com[i]);
	}
	cout << d1.top() << endl;

	return 0;
}





Measured memory_bytes: 3196
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val l = Vector.fill(n)(sc.nextInt())

  def go(num: Int, xs: Vector[Int]): Int = {
    if (xs.exists(_ % 2 == 1)) num
    else go(num + 1, xs.map(_ / 2))
  }

  println(go(0, l))
}


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

#define ll long long
#define ull unsigned long long

using namespace std;

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

	vector <int> b(n-1);
	for (int ii = 0; ii < n-1; ++ii){
		cin >> b[ii];
	}

	int ans = 0;
	ans += b[0];
	for (int ii = 0; ii < n-2; ++ii){
		ans += min(b[ii], b[ii+1]);
	}
	ans += b[n-2];

	cout << ans << "\n";

	return 0;
}


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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 100010, mod = 1e9 + 7;

int x, sum;

int main()
{
    cin >> x;

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

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;
string s;
int t;
int main()
{
	cin>>s;
	t=s.size();
	rep(i,t-1)
	{
		if(s[i]==s[i+1])
		{
			cout<<i+1<<" "<<i+2<<endl;
			return 0;
		}
	}
	rep(i,t-2)
	{
		if(s[i]==s[i+2])
		{
			cout<<i+1<<" "<<i+3<<endl;
			return 0;
		}
	}
	cout<<"-1 -1"<<endl;
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(){
    int i , x;
    i = 1;
    while (2){
        cin >> x;
        if (x == 0){
            break;
        } else{
            cout << "Case " << i ++ << ": " << x << endl ; 
        }
    }
    return 0;
}


Measured memory_bytes: 3072
p = []
x,n = gets.split(" ").map(&:to_i)
p = gets.split(" ").map(&:to_i)
dd = 0
 puts x if n == 0
 exit if n == 0
(p.max-x+2).times do |i|
	dd = x-i unless p.include?(x-i)
	break unless p.include?(x-i)
	dd = (x+i) unless p.include?((x+i))
 	break unless p.include?((x+i))
end

puts dd

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

int N;
vector<string> v;

int sub(int start) {
    vector<int> used(N, -1);
    set<int> now;
    now.insert(start);
    int ans = 0;

    while (now.size() > 0) {
        set<int> next;
        ans++;
        for (auto i : now) used[i] = ans;
        for (auto i : now) {
            for (int j = 0; j < v[i].size(); j++) {
                if (v[i][j] == '1') {
                    if (used[j] != (ans - 1) && used[j] != -1) return -1;
                    if (used[j] == -1) {
                        next.insert(j);
                    }
                }
            }
        }
        now = next;
    }


    return ans;
}

int main() {
    cin >> N;
    v.resize(N);
    for (auto &i : v) cin >> i;

    int ans = -1;
    for (int i = 0; i < N; i++) {
        ans = max(ans, sub(i));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string>
#include <iostream>
#include <map>
using namespace std;

const int mod = 998244353;

map<string, int> fc,gc;
int g(string s);

int f(string s)
{
	if (fc.count(s)) return fc[s];
	int &r = fc[s];

	for (int k=2;k<=s.length();k++) if (s.length() % k == 0){
		int l = s.length()/k;
		string nw(l,'1');
		for (int i=0;i<s.length();i++) if (s[i] == '0') nw[i%l] = '0';
		r = (r + g(nw)) % mod;
	}

	return r;
}

int g(string s)
{
	if (gc.count(s)) return gc[s];
	int &r = gc[s];
	r = f(s);
	for (int k=1;k<s.length();k++){
		r = (r + (long long) f(s.substr(0,k)) * g(s.substr(k))) % mod;
	}

	return r;
}

int main()
{
	fc["0"] = 1; fc["1"] = 2;
	string s; cin >> s;
	cout << g(s);

	return 0;
}

Measured memory_bytes: 12416
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int n,r[2000001]={0},d[2000001]={0};
int V,f[2000001]={0},z=0;
vector<int> G[2000001],ans;
int dfs(int x){
    if(r[x]&&!f[x]) z=1;
    if(z||r[x]) return 0;
    r[x]=1;
    for(auto i:G[x]) dfs(i);
    ans.push_back(x);
    f[x]=1;
}
void tsort(){
    rep(i,V) dfs(i+1);
    reverse(all(ans));
}
int dp[2000001]={0};
int longpass(){
    for(auto i:ans)for(auto j:G[i]) dp[j]=max(dp[j],dp[i]+1);
    return *max_element(dp+1,dp+V+1);
}
int A[1000][1000];
int main(){
    cin>>n;
    map<P,int> B;
    int p=1;
    rep(i,n)rep(j,n-1){
        cin>>A[i][j];
        int a=min(i+1,A[i][j]),b=max(i+1,A[i][j]);
        if(B[P(a,b)]==0) B[P(a,b)]=p,p++;
        A[i][j]=B[P(a,b)];
    }
    rep(i,n)rep(j,n-2){
        G[A[i][j]].push_back(A[i][j+1]);
    }
    V=n*(n-1)/2;
    tsort();
    if(z) cout<<-1;
    else cout<<longpass()+1;
    cout<<"\n";
}

Measured memory_bytes: 112752
#include<queue>
#include<ctime>
#include<vector>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<memory.h>
#include<map>
#include<ctime>
#include<algorithm>
#include<ctime>
#define ll int
#define For(i,j,k)  for(ll i=j;i<=k;++i)
#define FOr(i,j,k)  for(ll i=j;i>=k;--i)
#define ld double
using namespace std;
inline ll read(){   ll 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*10+ch-'0';ch=getchar();}  return x*f; }
inline void wrote(ll x){    if (x<0) putchar('-'),x=-x; if (x>=10) wrote(x/10);   putchar(x%10+'0');  }
inline void writeln(ll x){ wrote(x);   puts("");   }
const ll sz=(1<<15),N=16;
ll n,m,f[sz][N],g[sz][N],mp[N][N],cur[sz];
int main(){	
//	freopen("a.in","r",stdin);
	n=read();	m=read();
	while(m--){	ll x=read()-1,y=read()-1,w=read();	mp[x][y]=mp[y][x]=w;	}
	For(i,0,n-1)	cur[1<<i]=i;
	ll all=(1<<n)-1;
	For(S,0,all)	For(i,0,n-1)	if ((S>>i)&1)	For(j,0,n-1)	f[S][j]+=mp[i][j];//S->j所有路 
	memset(g,60,sizeof g);
	For(S,1,all)	g[S][0]=0;
	For(S,1,all)	For(i,0,n-1)	if ((S>>i)&1)	for(ll T=all^S;T;T=(T-1)&(all^S)){
		ll ans=0;
		for(ll j=T;j;j-=j&-j)	ans+=f[S][cur[j&-j]];
		if ((T>>(n-1))&1){	if (mp[i][n-1])	g[S|T][n-1]=min(g[S|T][n-1],g[S][i]+ans-mp[i][n-1]);	}
		else	For(j,0,n-1)	if (mp[i][j]&&((T>>j)&1))	g[S|T][j]=min(g[S|T][j],g[S][i]+ans-mp[i][j]);
	}ll answ=1e9+7;
	For(S,1,all){
		ll T=S^all,ans=0;
		For(i,0,n-1)	if ((T>>i)&1)	ans+=f[S][i];
		answ=min(answ,ans+g[S][n-1]);
	}writeln(answ);
}

Measured memory_bytes: 4224
#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; 
      
}


Measured memory_bytes: 3084
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<memory.h>
#include<stdlib.h>
int i, l, flag[15];
unsigned long long sum, sum1;
char s[15];
void find(int k, int index)
{
	int j;
	unsigned long long k1 = 1, p = 0;
	if (k > i)
	{
		for (j = l - 1; j >= 0; j--)
		{
			p = p + k1*(s[j] - 48);
			k1 = k1 * 10;
			if (j == 0 || flag[j - 1])
			{
				k1 = 1;
				sum += p;
				//sum1 += p;
				//printf(" %d", p);
				p = 0;
			}
		}
		//printf("=%d\n", sum1);
		//sum1 = 0;
		return;
	}
	for (j = index + 1; j < l - 1; j++)
	{
		flag[j] = 1;
		find(k + 1, j);
		flag[j] = 0;
	}
}
int main(void)
{
	scanf("%s", s);
	l = strlen(s);
	for (i = 0; i < l; i++)
	{
		find(1, -1);
	}
	printf("%llu", sum);
	return 0;
}

Measured memory_bytes: 128
S=str(input())
if 'SUN'in S:
    print(7)
elif 'MON' in S:
    print(6)
elif 'TUE' in S:
    print(5)
elif 'WED' in S:
    print(4)
elif 'THU' in S:
    print(3)
elif 'FRI' in S:
    print(2)
elif 'SAT' in S:
    print(1)

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

using namespace std;
typedef long long ll;

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

  int a[2][N];
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < N; j++) {
      cin >> a[i][j];
    }
  }

  for (int j = 0; j < N -1; j++) {
    a[0][j + 1] += a[0][j];
  }
  for (int j = N -1; j > 0; j--) {
    a[1][j - 1] += a[1][j];
  }

  int sum = 0;
  for (int j = 0; j < N; j++) {
    sum = max(sum, a[0][j] + a[1][j]);
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
from functools import lru_cache


def solve(n, a, b, c, d):

    @lru_cache(maxsize=None)
    def func(n):
        if n == 0:
            return 0
        if n == 1:
            return d
        else:
            # まずは全てdで増やした場合をセット
            coin = d * n

            # 2倍するケースを試す
            div, mod = divmod(n, 2)

            if mod == 0:
                coin = min(coin, func(div) + a)
            else:
                coin = min(coin, func(div) + a + d, func(div + 1) + a + d)

            # 3倍するケースを試す
            div, mod = divmod(n, 3)

            if mod == 0:
                coin = min(coin, func(div) + b)
            elif mod == 1:
                coin = min(coin, func(div) + b + d, func(div + 1) + b + 2 * d)
            else:
                coin = min(coin, func(div) + b + 2 * d, func(div + 1) + b + d)

            # 5倍するケースを試す
            div, mod = divmod(n, 5)

            if mod == 0:
                coin = min(coin, func(div) + c)
            elif mod == 1:
                coin = min(coin, func(div) + c + d, func(div + 1) + c + 4 * d)
            elif mod == 2:
                coin = min(coin, func(div) + c + 2 * d, func(div + 1) + c + 3 * d)
            elif mod == 3:
                coin = min(coin, func(div) + c + 3 * d, func(div + 1) + c + 2 * d)
            else:
                coin = min(coin, func(div) + c + 4 * d, func(div + 1) + c + d)

        return coin
    return func(n)


t = int(input())
ans = []
for i in range(t):
    n, a, b, c, d = map(int, input().split())
    ans.append(solve(n, a, b, c, d))

print(*ans, sep="\n")

Measured memory_bytes: 20764
import java.util.*;
public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		new AOJ0594().doIt();
	}
	
	class AOJ0594{
		int w,h,n;
		
		long keisan(int ax,int ay,int bx,int by){
			int sx = bx-ax;
			int sy = by-ay;
			if(sx>=0&&sy>=0)return Math.max(sx, sy);
			else if(sx<=0&&sy<=0)return Math.max(-sx, -sy);
			else if(sx>0&&sy<0)return sx-sy;
			else return sy-sx;
		}
		
		void doIt(){
			w = in.nextInt();h = in.nextInt();n = in.nextInt();
			int sx = in.nextInt()-1,sy = in.nextInt()-1;
			long result = 0;
			for(int i=1;i<n;i++){
				int ax = in.nextInt()-1;
				int ay = in.nextInt()-1;
				result += keisan(sx,sy,ax,ay);
				sx = ax; sy = ay;
			}
			System.out.println(result);
		}
	}
	
}

Measured memory_bytes: 25464
def main():
    X = int(input())
    menu = [100, 101, 102, 103, 104, 105]
    x_list = [False] * (X + 1)
    x_list[0] = True
    for i in range(X + 1): 
        if x_list[i] is True:
            for yen in menu:
                if i + yen <= X:
                    x_list[i + yen] = True
    if x_list[X] is True:
        print('1')
    else:
        print('0')


if __name__ == '__main__':
    main()


Measured memory_bytes: 39792
#include "bits/stdc++.h"
using namespace std;
#define mod 1000000007
#define all(c) begin(c),end(c)
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
using ll = long long;
int dd[] = { 0, 1, 0, -1, 0 }; //→↓←↑

void solve()
{
	int N, M;
	vector<int> C;
	vector<vector<ll>> dp;
	while (true)
	{
		cin >> N >> M;
		if (N == 0 && M == 0)break;
		C = vector<int>(M);
		for (int i = 0; i < M; i++)
		{
			cin >> C[i];
		}
		dp = vector<vector<ll>>(N + 1, vector<ll>(256, LLONG_MAX / 3));
		dp[0][128] = 0;
		int x;
		for (int i = 0; i < N; i++)
		{
			cin >> x;
			for (int j = 0; j < 256; j++)
			{
				for (int k = 0; k < M; k++)
				{
					int l = min(max(j + C[k], 0), 255);
					chmin(dp[i + 1][l], dp[i][j] + (x - l) * (x - l));
				}
			}
		}
		ll ans = LLONG_MAX;
		for (int i = 0; i < 256; i++)
		{
			chmin(ans, dp[N][i]);
		}
		cout << ans << endl;
	}
}

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


Measured memory_bytes: 84368
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
	int i=0;
	int length=0;
	int count1=0;
	int count2=0;
//	char str[256];

	char *str;
	
	str = (char *)malloc(100000+1);
	
	if (str == NULL) {
		return -1;
	}
	 
	
	scanf("%s", str);
	length=strlen(str);
	
	for(i=0;i<length;i++)
	{
		if(str[i]=='1')
		{
			count1++;
		}
		else
		{
			count2++;
		}
	}
	
	if(count1>count2)
	{
		printf("%d\n",count2*2);
	}
	else
	{
		printf("%d\n",count1*2);
	}
	return 0;
}

Measured memory_bytes: 256
#include <utility>
#include <cstdio>
#include <cmath>
#include <climits>
#include <iostream>
using namespace std;

//---- How many ways?
int main(void){
    while(1){
        int n, x, cnt=0;
        cin >> n >> x;
        if(n==0 && x==0){break;}
        for(int s=1; s<=n; s++){
            for(int m=s+1; m<(x-s+1)/2; m++){
                //cout << "s:" << s << endl << "m:" << m << endl;
                int l=x-s-m;
                if(s<=n && m<=n && l<=n){
                    cnt+=1;
                    //cout << s << m << l << endl;
                }
                
            }
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 3020
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int N; cin >> N;
    int gA, sA, bA, gB, sB, bB; cin >> gA >> sA >> bA >> gB >> sB >> bB;
    vector<Int> dp(N+1);
    dp[0] = 0;
    for (int i = 0; i <= N; i++) {
        dp[i] = i;
        if (i >= gA) dp[i] = max(dp[i], dp[i-gA] + gB);
        if (i >= sA) dp[i] = max(dp[i], dp[i-sA] + sB);
        if (i >= bA) dp[i] = max(dp[i], dp[i-bA] + bB);
    }
    Int M = dp[N];
    dp = vector<Int>(M+1);
    for (int i = 0; i <= M; i++) {
        dp[i] = i;
        if (i >= gB) dp[i] = max(dp[i], dp[i-gB] + gA);
        if (i >= sB) dp[i] = max(dp[i], dp[i-sB] + sA);
        if (i >= bB) dp[i] = max(dp[i], dp[i-bB] + bA);
    }
    cout << dp[M] << '\n';
    return 0;
}


Measured memory_bytes: 195584
wordslist = []
last = ""
num = gets.to_i

for i in 1..num do
    word = gets.chomp
    if wordslist.include?(word)
        puts "No"
        exit
    end
    wordslist.push(word)
    if i > 1
        if word[0] != last
            puts "No"
            exit
        end
    end
    last = word[-1]
end

puts "Yes"


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define RFOR(i, m, n) for (ll i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << (ele) << "\n"
#define print10(ele) cout << fixed << setprecision(10) << (ele) << "\n"

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int main() {
  int n, m;
  cin >> n >> m;
  ivec a(n);
  ll sum = 0;
  REP(i, n) {
    cin >> a[i];
    sum += a[i];
  }
  sort(RALL(a));

  if (a[m - 1] * 4 * m >= sum) {
    print("Yes");
  } else {
    print("No");
  }
  return 0;
}

Measured memory_bytes: 256
M_ab=400
M_n=40
inf=float('inf')
n,Ma,Mb=map(int,input().split())
A,B,C=[],[],[]
for _ in range(n):
    a,b,c=map(int,input().split())
    A.append(a)
    B.append(b)
    C.append(c)
DP=[[[inf]*(M_ab+1) for _ in range(M_ab+1)] for _ in range(M_n+1)]
DP[0][0][0]=0
for i in range(n):
    for ca in range(M_ab+1):
        for cb in range(M_ab+1):
            if DP[i][ca][cb]==inf:
                continue
            DP[i+1][ca][cb]=min(DP[i+1][ca][cb],DP[i][ca][cb])
            DP[i+1][ca+A[i]][cb+B[i]]=min(DP[i+1][ca+A[i]][cb+B[i]],DP[i][ca][cb]+C[i])
ans=inf
for ca in range(1,M_ab+1):
    for cb in range(1,M_ab+1):
        if ca*Mb==cb*Ma:
            ans=min(ans,DP[n][ca][cb])
if ans==inf:
    ans=-1
print(ans)

Measured memory_bytes: 59500
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

#include <map>

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    map<string, int> m;
    int mx = -1;
    REP(i, 0, n) {
        string s;
        cin >> s;
        m[s]++;
        chmax(mx, m[s]);
    }
    vector<string> ans;
    for (auto &ss : m) {
        if (ss.second == mx) {
            ans.push_back(ss.first);
        }
    }
    sort(ans.begin(), ans.end());
    for (auto &ss : ans) {
        cout << ss << endl;
    }

    return 0;
}


Measured memory_bytes: 25584
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long k = sc.nextLong();
		long d = sc.nextLong();
		boolean isMinus = false;
		if (x < 0) {
		    isMinus = true;
		    x = -x;
		}
		if (x / d > k) {
		    System.out.println(x - d * k);
		    return;
		}
		long mod = x % d;
		long div = x / d;
		k -= div;
		if (k % 2 == 0) {
		    System.out.println(mod);
		} else {
		    System.out.println(Math.abs(mod - d));
		}
	}
}


Measured memory_bytes: 35700
#-------最強ライブラリSCC(Python) ver25252------
class scc_graph:
  # n 頂点数
  def __init__(s, n): 
    s._n = n
    s.g = {}
    s.rg = {}
  def num_vertices(s): return s._n
  # 辺を追加 frm 矢元 to 矢先
  # O(1)
  def add_edge(s, frm, to): 
    if frm in s.g: s.g[frm].append(to)
    else: s.g[frm] = [to]
    if to in s.rg: s.rg[to].append(frm)
    else: s.rg[to] = [frm]

  # グループの個数と各頂点のグループidを返す
  def scc_ids(s):
    def dfs(v):
      stack = [v]
      while stack:
        t = stack.pop()
        vis[t] = True
        if t not in s.g:
          vs.append(t)
          continue
        for i in s.g[t]:
          if not vis[i]:
            stack.append(t)
            stack.append(i)
            break
        else:
          vs.append(t)

    def rdfs(v, n):
      stack = [v]
      vis[v] = True
      ids[v] = n
      while stack:
        t = stack.pop()
        vis[t] = True
        if t not in s.rg: continue
        for i in s.rg[t]:
          if not vis[i]:
            ids[i] = n
            stack.append(i)

    vis = [False] * s._n 
    vs = []
    ids = [-1] * s._n
    for i in range(s._n):
      if not vis[i]:
        dfs(i)
    group_num = 0
    vis = [False] * s._n 
    for i in vs[::-1]:
      if not vis[i]:
        rdfs(i, group_num)
        group_num += 1
    return group_num, ids 

  # 強連結成分となっている頂点のリストのリスト トポロジカルソート済み
  # O(n + m)
  def scc(s):
    ids = s.scc_ids()
    group_num = ids[0]
    counts = [0] * group_num
    for x in ids[1]: counts[x] += 1
    groups = [[] for _ in range(group_num)]
    for i in range(s._n):
      groups[ids[1][i]].append(i)
    return groups

#-------最強ライブラリここまで------

import sys
def main():
  input = sys.stdin.readline

  n, m = list(map(int, input().split()))
  ab = [list(map(int, input().split())) for _ in range(m)]

  g = scc_graph(n)

  for i in range(m):
    u, v = ab[i]
    g.add_edge(u, v)

  scc = g.scc()

  print(len(scc))

  for v in scc:
    print(len(v), end = " ")
    for x in v:
      print(x, end = " ")
    print("")

main()


Measured memory_bytes: 304192
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF 1e9
#define rep(i,n) for(int i=0;i<n;i++)
#define eq(a,b) (fabs(a-b)<EPS)
#define eqv(a,b) (eq(a.real(),b.real())&&eq(a.imag(),b.imag()))

typedef complex<double> P;

bool used[401];
char c;
int n;
double x,y;
P p[401];

double dot(P a, P b) {
  return (a.real() * b.real() + a.imag() * b.imag());
}

int main(){
	while(cin>>n&&n){
		fill(used,used+401,0);
		int m=0;
		p[0]=P(0.0,0.0);
		rep(i,n){
			cin>>x>>y;
			p[i+1]=P(x,y);
		}
		double ans=0.0;
		P v(0.0,1.0);
		rep(h,n){
			used[m]=1;
			int nx;
			double M=-2;
			rep(i,n+1)if(!used[i]&&(dot(v,(p[i]-p[m])/abs(p[i]-p[m]))>M+EPS||
				eq(dot(v,(p[i]-p[m])/abs(p[i]-p[m])),M)&&abs(p[i]-p[m])<abs(p[nx]-p[m]))){/*cout<<p[i]<<" "<<abs(p[i]-p[m])<<endl;*/M=dot(v,(p[i]-p[m])/abs(p[i]-p[m]));nx=i;}
			v=(p[nx]-p[m])/abs(p[nx]-p[m]);
			//cout<<p[nx]<<" "<<v<<" "<<M<<" "<<abs(p[nx]-p[m])<<endl;
			ans+=abs(p[nx]-p[m]);
			m=nx;
		}
		printf("%.1f\n",ans);
	}
}

Measured memory_bytes: 0
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]

ufs = [-1] * N

def ufs_root(a):
	if ufs[a] < 0:
		return a
	ufs[a] = ufs_root(ufs[a])
	return ufs[a]

def ufs_size(a):
	return -ufs[ufs_root(a)]

def ufs_same(a, b):
	return (ufs_root(a) == ufs_root(b))

def ufs_merge(a, b):
	if ufs_same(a, b):
		return
	hi, lo = ufs_root(a), ufs_root(b)
	if ufs_size(hi) < ufs_size(lo):
		hi, lo = lo, hi
	ufs[hi] += ufs[lo]
	ufs[lo] = hi

result = [(N * (N - 1)) // 2]
for a, b in AB[::-1]:
	a, b = a - 1, b - 1
	if ufs_same(a, b):
		result += [result[-1]]
		continue
	result += [result[-1] - (ufs_size(a) * ufs_size(b))]
	ufs_merge(a, b)

for v in result[::-1][1:]:
	print(v)


Measured memory_bytes: 36012
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main(){
    int n;
    cin >> n;
    string s;
    map<string, int> freq;
    for(int i = 0; i < n; i ++){
        cin >> s;
        freq[s] ++;
    }
    cout << freq.size();
}

Measured memory_bytes: 19232
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

typedef long long int llint;

int N;

int main() {
	cin >> N;
	int root = sqrt(N+1);
	llint ans = 0;
	vector<llint> f(N + 1, 2);
	f[1] = 1;

	for (int i = 2; i <= root; i++) {
		f[i * i]++;
		for (int j = i * i + i; j <= N; j += i) {
			f[j] += 2;
		}
	}

	for (int K = 1; K <= N; K++) {
		ans += K * f[K];
	}
	cout << ans << endl;
}

Measured memory_bytes: 81428
#include <bits/stdc++.h>
//#include <cstdio>
//#include <cstring>
//#include <iostream>
//#include <algorithm>
using namespace std;
typedef long long ll;
const  int maxx=1e6+100;
const int INF=1e9;
const int MOD=1e9+7;
int a[maxx],b[maxx],c[maxx];
int main()
{
    int n;
    scanf("%d",&n);
    int k;
    for(int i=0; i<n; i++){
        scanf("%d",&a[i]);
    }
    for(int i=0; i<n; i++){
        scanf("%d",&b[i]);
    }
    for(int i=0; i<n; i++){
        scanf("%d",&c[i]);
    }
    sort(a,a+n);
    sort(c,c+n);
    ll u,v;
    ll ans=0;
    int p;
    for(int i=0; i<n; i++){
        p=b[i];
        u=lower_bound(a,a+n,p)-a;
        v=n-(upper_bound(c,c+n,p)-c);
        //cout<<"*"<<u<<" "<<v<<endl;

        ans+= u*v;

    }
    printf("%lld\n",ans);
    return 0;
}


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

using namespace std;
#define int long long
const int mod=1e9+7;

signed main(){

   int N, A, B;
   cin>> N>> A>> B;
   int a[N];
   for(int i=0; i<N; i++) cin>> a[i];

   int d=0;
   for(int i=0; i<N-1; i++){
      d+=min(B, (a[i+1]-a[i])*A);
   }

   cout<< d<< endl;

   return 0;
}


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

using namespace std;

int solve(int A,int B,int C,int X)
{
    int ans = 0;
    for(int i = 0; i <= A; ++i)
    {
        for(int j = 0; j <= B; ++j)
        {
            for(int k = 0; k <= C; ++k)
            {
                int tmp = i * 500 + j * 100 + k * 50;
                if(tmp == X)
                    ans++;
            }
        }
    }
    return ans;
}

int main()
{
    int a,b,c,x;
    while(cin>>a>>b>>c>>x)
    {
        cout<<solve(a,b,c,x)<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int X = sc.nextInt();
      int prime = X;
      int mid = prime/2;
      boolean flag = false;
      while (true){
        for(int i = 2; i <= mid; ++i){
        	if(prime % i == 0)
            {
              flag = true;
              break;
            }
        }
        if (!flag){
          break;
        }
        else
          flag = false;
          prime++;
      }
      System.out.println(prime);
    }
}

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

#include <boost/algorithm/string/classification.hpp>  // is_any_of
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/math/tools/minima.hpp>
#include <boost/multi_array.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>

const int MOD = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < (n); ++i)

namespace adaptor = boost::adaptors;
using namespace std;
using boost::irange;
using boost::algorithm::join;
using boost::algorithm::replace_all;
using boost::algorithm::split;
using boost::math::tools::brent_find_minima;
using boost::multiprecision::cpp_int;
using ll = long long;
using P = pair<int, int>;

// TOP
void Main()
{
	int n;
	cin >> n;
	bitset<20> bs;
	int super;
	super = 0;
	rep(i, n)
	{
		int x;
		cin >> x;
		if (x < 400)
			bs.set(0);
		else if (x < 800)
			bs.set(1);
		else if (x < 1200)
			bs.set(2);
		else if (x < 1600)
			bs.set(3);
		else if (x < 2000)
			bs.set(4);
		else if (x < 2400)
			bs.set(5);
		else if (x < 2800)
			bs.set(6);
		else if (x < 3200)
			bs.set(7);
		else
			super++;
	}
	int minv;
	if (bs.count() == 0 && super > 0)
		minv = 1;
	else
		minv = bs.count();

	cout << minv << ' ' << bs.count() + super << endl;
}
// END

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


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

int main() {
	int h, m, h2, m2, k, calcH, ans;
	cin >> h >> m >> h2 >> m2 >> k;
	calcH = h2 - h;
	if (calcH < 1) {
		cout << m2 - m - k << endl;
	}
	else {
		ans = calcH * 60;
		if (m2 - m > -1) {
			ans += m2 - m;
		}
		else {
			ans -= m - m2;
		}
		cout << ans - k << endl;
	}
}

Measured memory_bytes: 3588
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int N=505;
int n,a[N],sum,k,Ans,flag;
int p[N],q[N];
vector<int>fac;
inline void Did(int x)
{
	for(int i=1;i*i<=x;++i)
	{
		if(!(x%i))
		{
			fac.push_back(i);
			if(i*i<x) fac.push_back(x/i);
		}
	}
}
inline bool cmp(int a,int b) {return a>b;}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]),sum+=a[i];
	Did(sum);
	for(int i=0;i<(int)fac.size();++i)
	{
		int g=fac[i];
		int sum1=0,sum2=0;
		for(int j=1;j<=n;++j)
		{
			p[j]=a[j]%g,q[j]=g-a[j]%g;
			sum1+=q[j];
		}
		sort(p+1,p+n+1),sort(q+1,q+1+n,cmp);
		for(int j=1;j<=n;++j)
		{
			sum2+=p[j],sum1-=q[j];
			if(sum1==sum2 && sum1<=k) {Ans=max(Ans,g);break;}
		}
	}
	printf("%d",Ans);
	return 0;
}

Measured memory_bytes: 384
n,m,v,p = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)

#　せっかくなのであとでmarginを前計算してm*v以上をbisect
def isOK(x):
  border = a[x-1]
  if border + m < a[p-1]:
    return False
  elif x <= p:
    return True
  else:
    margin = m * n
    for i in range(p-1,x-1):
      margin -= a[i] - border
    if margin >= m*v:
      return True
    else:
      return False

def binary_search():
    ok = p-1
    ng = n+1
    while abs(ok-ng) > 1:
        mid = (ok+ng)//2
        if isOK(mid):
            ok = mid
        else:
            ng = mid
    return ok

ans = binary_search()  
print(ans)

Measured memory_bytes: 14484
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#define ll long long
#define inf  999999999
#define con 131072
#define pa pair<int,int>

using namespace std;

int a[300000];

int sums(int i,int j ){
if(i==j) return a[i];
else if(i%2==1) return a[i]+sums(i+1,j);
else if(j%2==0) return a[j]+sums(i,j-1);
else return sums(i/2,j/2);
}


void upd(int x,int y){
a[x]=a[x]+y;
x=x/2;
while(x != 0){
a[x]=a[2*x+1]+a[2*x];
x=x/2;
}
}


int main(){
int n,q,com,x,y;
for(int i=0;i<270000;i++) a[i]=0;
cin>>n>>q;
for(int i=0;i<q;i++){
cin>>com>>x>>y;
if(com==1) cout<<sums(x+con,y+con)<<endl;
else upd(x+con,y);

}



	return 0;
}

Measured memory_bytes: 2212
r, c = map(int, raw_input().split())
t = []
for i in range(r):
    t.append(map(int, raw_input().split()))
    t[i].append(sum(t[i]))

t.append([sum([t[j][i] for j in range(r)]) for i in range(c+1)])

for i in range(r+1):
    print(" ".join(map(str, t[i])))

Measured memory_bytes: 4324
#
# File    : D2.rb
# Author  : Kazune Takahashi
# Created : 2018-12-2 21:41:17
# Powered by Visual Studio Code
#

require 'prime'

n = gets.to_i

hash = {}

for i in 2...100
  if i.prime?
    hash[i] = 0
  end
end

for i in 1..n
  i.prime_division.each{|prime, cnt|
    hash[prime] += cnt
  }
end

# p hash

ary = Array.new(100){0}

hash.each{|prime, cnt|
  ary[cnt] += 1
}

98.downto(0){|i|
  ary[i] += ary[i + 1]
}

ans = 0
ans += ary[74]
ans += (ary[4] - 1) * ary[14]
ans += (ary[2] - 1) * ary[24]
ans += (ary[2] - 2) * ary[4] * (ary[4] - 1) / 2

puts ans


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

using namespace std;

namespace {
constexpr char diff = 'A' - 'a';
}

int main() {
  int N, K;
  string S;
  cin >> N >> K >> S;
  --K;
  S[K] = S[K] - diff;
  
  cout << S << endl;
  
  return 0;
}


Measured memory_bytes: 3604
//作者：中国江苏省南京市李硕睿
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
int gcd(int a,int b){
	int temp;
	if (a<b){
		temp=a;
		a=b;
		b=temp;
	}
	if (a%b==0)
		return b;
	gcd(b,a%b);
}
int main(){
	int n,k,i;
	while (scanf("%d%d",&n,&k)==2){ 
		vector<int> a(n);
		for (i=0;i<n;i++)
			scanf("%d",&a[i]);
		sort(a.begin(),a.end());
		int g=a[0];
		for (int i=1;i<n;i++)
			g=gcd(g,a[i]);
		bool f=k%g==0 && a[n-1]>=k;
		string ans=f ? "POSSIBLE" : "IMPOSSIBLE";
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 640
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
    sc.Scan()
    i, _ := strconv.Atoi(sc.Text())
    return i
}

func nextIntArr(n int) []int {
    var a []int
    for i := 0; i < n; i++ {
        a = append(a, nextInt())
    }
    return a
}

// 数値を桁区切りのスライスにする
func digit(n int, list []int) []int {
   if n > 0 {
       return digit(n/10, append(list, n%10))
   }
   return list
}


func main() {
    sc.Split(bufio.ScanWords)
    n := nextInt()
    a := nextIntArr(n)
    alice := 0
    bob := 0
    for i := 0; i < n; i++ {
        max := 0
        for j := 0; j < n; j++ {
            if a[j] > a[max] {
                max = j
            }
        }
        if i % 2 == 0 {
            alice += a[max]
        } else {
            bob += a[max]
        }
        a[max] = 0
    }
    fmt.Println(alice - bob)
}


Measured memory_bytes: 640
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt(); Long [] a = new Long[n + 1];
        for (int i = 1; i <= n; i++) a[i] = sc.nextLong();
        Arrays.sort(a, 1, n + 1, Comparator.reverseOrder());
        long ans = a[1];
        for (int i = 2; i <= (n + 1) / 2; i++) {
            ans += a[i];
            if (n >= 2 * i) ans += a[i];
        }
        out.println(ans);
        out.close();
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

Measured memory_bytes: 59812
#include <iostream>
#include <cstdlib>
#include <cstdio>
#define N 200011
#define INF 0x7f7f7f7f
#define int long long
using namespace std;
int L[N],R[N],maxx1[N],maxx2[N],fa[N],siz[N],n,indexx[N],tot,Mark[N],ans;
char s[N];
struct apple{
	int v,nxt;
}edge[N*4];
void addedge(int x,int y){
	edge[++tot].v=y;
	edge[tot].nxt=indexx[x];
	indexx[x]=tot;
}
void dfs1(int u,int f){
	if(Mark[u]){
		siz[u]=1;
		L[u]=0;
	}
	else L[u]=INF;
	fa[u]=f;
	maxx1[u]=0;
	maxx2[u]=-INF;
	int t=indexx[u],vv;
	while(t){
		vv=edge[t].v;
		if(vv!=f){
			dfs1(vv,u);
			siz[u]+=siz[vv];
			if(maxx1[vv]+1>maxx1[u]){
				maxx2[u]=maxx1[u];
				maxx1[u]=maxx1[vv]+1;
			}
			else if(maxx1[vv]+1>maxx2[u]){
				maxx2[u]=maxx1[vv]+1;
			}
			if(siz[vv]) L[u]=min(L[u],maxx1[vv]+1);
		}
		t=edge[t].nxt;
	}
}
void dfs(int u){
	int temp;
	R[u]=min(maxx1[u]-1,maxx2[u]+1);
	if(R[u]>=L[u]) ans+=R[u]-L[u]+1;
	int t=indexx[u],vv;
	while(t){
		vv=edge[t].v;
		if(vv!=fa[u]){
			if(maxx1[u]==maxx1[vv]+1){
				temp=maxx2[u]+1;
			}
			else temp=maxx1[u]+1;
			if(temp>maxx1[vv]) maxx2[vv]=maxx1[vv],maxx1[vv]=temp;
			else if(temp>maxx2[vv]) maxx2[vv]=temp;
			if(siz[1]-siz[vv]) L[vv]=min(L[vv],temp);
			dfs(vv);
		}
		t=edge[t].nxt;
	}
}
signed main(){
	int x,y;
	scanf("%lld",&n);
	for(int i=1;i<n;i++){
		scanf("%lld%lld",&x,&y);
		addedge(x,y);
		addedge(y,x);
	}
	scanf("%s",s+1);
	for(int i=1;i<=n;i++) Mark[i]=s[i]-'0';
	dfs1(1,0);
	dfs(1);
	printf("%lld",ans+1);
	return 0;
}

Measured memory_bytes: 28544
object Main extends App {

  val Array(n, k) = scala.io.StdIn.readLine().split(" ").map(_.toInt)
  val hArr = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  def solve()  = {
    hArr.count(_ >= k)
  }
  println(solve)

}


Measured memory_bytes: 41708
# 関数を使った場合
N, A, B = map(int, input().split())
ans = 0

def FindSumOfDigits(x):
    count = 0
    while x>0:
        count += x%10
        x = x//10
    
    return count
    

for n in range(1, N+1):
    count = FindSumOfDigits(n)
    if A<= count <=B:
        ans += n

print(ans) 

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

int main() {
  int X;
  int Y;
  cin >> X;
  cin >> Y;
  if(Y % 2 == 1){
    cout << "No";
  }
  else{
    if(Y >= X * 2 && Y <= X * 4){
      cout << "Yes";
    }
    else{
      cout << "No";
    }
  }
}

Measured memory_bytes: 3636