akhauriyash/Code-Regression huggingface dataset:
# include "bits/stdc++.h"
 
using namespace std;
 
#define endl "\n"
typedef long long int ll;
#define f first
#define s second
 
inline void fastio(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
inline void setPrecision(int n){cout.precision(n);}
 
//DEBUG
#define dbg(x) cerr<<(#x)<<": "<<x<<endl
#define dbgV(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgS(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgM(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
#define dbg2D(x) cerr<<(#x)<<": \n"; for(auto y: x) { for(auto it: y) cerr<<it<<" "; cerr<<endl; } cerr<<endl;
#define dbgA(x, n) cerr<<(#x)<<": "; for(int i=0;i<n;++i) cerr<<x[i]<<" "; cerr<<endl;
#define dbgVP(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
 
ll INF = 1e10;
int MOD = 1e9+7;

int main(){
    fastio();

    int h, a;
    cin >> h >> a;
    cout << (h + a - 1)/a;

    return 0;
}

/*

*/

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a;
  cin>>a;
  vector<int> b(a);
  vector<int> c(a);
  for(int i=0;i<a;i++){
    cin>>b.at(i);
  }
  for(int i=0;i<a;i++){
    cin>>c.at(i);
  }
  int d;
  for(int i=0;i<a;i++){
    if(b.at(i)>c.at(i))
      d+=b.at(i)-c.at(i);
  }
  cout<<d;
}

Measured memory_bytes: 256
# B - Exactly N points
n=int(input())

if n==1:
    print(1)
    exit()
t=0
acc=[]
for i in range(1,n+1):
    t+=i
    acc.append(t)
max_v=-1
for i in range(len(acc)-1):
    if acc[i]<n<=acc[i+1]:
        max_v=i+2
        break
ans=[]
ans.append(max_v)
cur=max_v
vv=acc[i+1]
vv-=cur
s=max_v

while vv and s<n:
    cur-=1
    if vv>cur and s+cur<=n:
        vv-=cur
        ans.append(cur)
        s+=cur
    elif vv<cur:
        continue
    elif vv==cur:
        vv-=cur
        ans.append(cur)
        s+=cur
for a in ans:
    print(a)


Measured memory_bytes: 187168
package main

import (
	"fmt"
)

func main() {

	var X int

	fmt.Scan(&X)

	okFlg := false

	for {

		okFlg = false

		for i:=2;i<X-1;i++{

			if X %i ==0{

				okFlg = true
			
				break
			}

		}

		if okFlg == false{

			break
		
		}else{

			X++
		}

	}

	fmt.Println(X)


}


Measured memory_bytes: 512
import math
import sys
#####sorting a dictionary by the values#####
def dict_sort(ans):
    ans=sorted(ans.items(),reverse=True,key=lambda kv:(kv[1]))
#####Primes till Nth#####
def seive_primes(n):
    flag=[0]*(n+10)
    flag[1]=flag[0]=1
    i=2
    while i*i<=n+1:
        if flag[i]==0:
            j=i*i
            while j<=n+1:
                flag[j]=1
                j+=i
        i+=1
    return flag
##### naive method for testing prime or not#####
def is_prime(n):
    if n==1:
        return 0
    for i in range(2,int(math.sqrt(n))+1):
        if n%i==0:
            return False
    return True
#####greatest common divisor of two numbers#####
def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)
#####least common multiplyer of two numbers#####
def lcm(a,b):
    return (a*b)//gcd(a,b)
#####function that return all the letters#####
def alphbates():
    return "abcdefghijklmnopqrstuvwxyz"
#####taking an array/list as input#####
def inp():
    ls=list(map(int,input().split()))
    return ls
#####taking multiple inputs#####
def mult_inp():
    return map(int,input().split())
#####Main function starts from here#####
s=input()
if s.isupper():
    print("A")
else:
    print("a")

Measured memory_bytes: 9076
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys

INF = float('inf')


def solve(X: int):
    return X//500*1000 + X % 500//5*5


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    print(f'{solve(X)}')


if __name__ == '__main__':
    main()


Measured memory_bytes: 74896
#include<cstdio>
#include<cmath>
long long a,b;
using namespace std;
int main(){
//  freopen("agc.in","r",stdin);
    scanf("%lld%lld",&a,&b);long long ans=0;
    if (a<0&&b<0&&a>=b) {ans+=2;ans+=abs(a-b);}
    if (a<0&&b<0&&a<b) {ans+=abs(a-b);}
    if (a<0&&b>0) {ans=1;ans+=abs(b+a);}
    if (a>0&&b<0) {ans=1;ans+=abs(b+a);}
    if (a>0&&b>0&&a<=b) {ans+=abs(b-a);}
    if (a>0&&b>0&&a>b) {ans=2;ans+=abs(b-a);}
    if (!a||!b) {
        if (a>b) ans+=abs(b-a)+1;else ans+=abs(b-a);
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 128
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(
        &mut std::io::stdin(),
        &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!(usize);
    let d = get!(usize);
    let mut vs = vec![];
    for _ in 0 .. n {
        let mut ps = vec![];
        for _ in 0 .. d {
            ps.push(get!());
        }
        vs.push(ps);
    }
    let mut ans = 0;
    
    for i in 0 .. n {
        for j in i+1 .. n {
            let mut dis = 0;
            for k in 0 .. d {
                let tmp = vs[i][k] - vs[j][k];
                dis += tmp * tmp;
            }
            let dis = (dis as f64).sqrt();
            let d1 = dis.ceil();
            let d2 = dis.floor();
            if d1 == d2 {
                ans += 1;
            }
        }
    }
    
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>

#define int long

const int INF = 1000000009;
const long LINF = 1123456789012345678;

int h, w;
char field[10][10];


signed main(){
	scanf("%ld %ld", &h, &w);
	for(int i = 0; i < h; i++){
		scanf("%s", field[i]);
	}
	for(int i = 0; i < h + w - 1; i++){
		int cnt = 0;
		for(int j = std::max(0l, i-w+1); j <= i; j++){
			if(field[j][i-j] == '#'){
				cnt++;
			}
		}
		//printf("%ld %ld\n", i, cnt);
		if(cnt != 1){
			printf("Impossible\n");
			return 0;
		}
	}
	printf("Possible\n");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

const double PI = 3.14159265358979323846;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(20);
	double a, b, h, m;
	cin >> a >> b >> h >> m;
	double hdeg = (h + m/60)/12 * 360;
	double mdeg = (m/60) * 360;
	double ddeg = abs(hdeg - mdeg);
	if (ddeg == 180) {
		cout << a+b; return 0;
	}
	else if (ddeg > 180) {
		ddeg = 360 - ddeg;
	}
	ddeg = ddeg * PI / 180.0;
	cout << sqrt(a*a + b*b - 2*a*b*cos(ddeg));
}

Measured memory_bytes: 4240
s = input().split()
intX = int(s[0])

if intX >= 400 and intX < 600:
    print('8')
elif intX >= 600 and intX < 800:
    print('7')
elif intX >= 800 and intX < 1000:
    print('6')
elif intX >= 1000 and intX < 1200:
    print('5')
elif intX >= 1200 and intX < 1400:
    print('4')
elif intX >= 1400 and intX < 1600:
    print('3')
elif intX >= 1600 and intX < 1800:
    print('2')
else :
    print('1')


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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	ll n,a,b;
	cin >> n >> a >> b;
	ll c = (a+b);
	ll cnt = n/c;
	ll cnt2 = n%c;
	cnt2 = min(a,cnt2);
	ll ans = cnt*a + cnt2;
	cout << ans << endl;
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 256
#include <stdio.h>

void calc_rectangle(int a, int b, int *s, int *l)
{
    *s = a * b;
    *l = (a + b) * 2;
}

int main(void)
{
    int a, b, s, l;

    scanf("%d %d", &a, &b);
    calc_rectangle(a, b, &s, &l);
    printf("%d %d\n", s, l);

    return 0;
}


Measured memory_bytes: 2668
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
#define PI 3.141592653589793
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
template<class T>inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;}
const ll INF = 1LL << 60;

//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

struct UnionFind {
    vector<ll> par,rank,con;
    UnionFind(ll n) : par(n,-1),rank(n,0),con(n,1) { }
    ll root(ll x){
        if (par[x]<0)return x;
        return par[x]=root(par[x]);
    }
    bool unite(ll x,ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        con[x] += con[y];
        return true;
    }
    bool same(ll x,ll y){
        ll rx=root(x);
        ll ry=root(y);
        return rx==ry;
    }
    ll size(int x) {
        return -par[root(x)];
    }
};


int main() {
    ll n,m,ans=1;
    cin >> n >> m;
    UnionFind uf(n);
    for (ll i=0;i<m;i++){
        ll a,b;
        cin >> a >> b;
        a--;
        b--;
        uf.unite(a,b);
    }
    bool visited[n];
    fill(visited,visited+n,false);
    for (ll i=0;i<n;i++){
        ans=max(ans,uf.size(i));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8260
def main():
    import sys
    from fractions import gcd
    input = sys.stdin.readline

    def init(init_val):
        #set_val
        for i in range(n):
            seg[i+num-1]=init_val[i]    
        #built
        for i in range(num-2,-1,-1) :
            seg[i]=gcd(seg[2*i+1],seg[2*i+2]) 
        
    def update(k,x):
        k += num-1
        seg[k] = x
        while k:
            k = (k-1)//2
            seg[k] = gcd(seg[k*2+1],seg[k*2+2])
        
    def query(p,q):
        if q<=p:
            return ide_ele
        p += num-1
        q += num-2
        res=ide_ele
        while q-p>1:
            if p&1 == 0:
                res = gcd(res,seg[p])
            if q&1 == 1:
                res = gcd(res,seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = gcd(res,seg[p])
        else:
            res = gcd(gcd(res,seg[p]),seg[q])
        return res



    n = int(input())
    a = tuple(map(int,input().split()))

    #####単位元######
    ide_ele = 0

    #num:n以上の最小の2のべき乗
    num =2**(n-1).bit_length()
    seg=[ide_ele]*2*num
    init(a)

    ans = -1
    for i in range(n):
        ans = max(ans,gcd(query(0,i),query(i+1,n)))
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 90080
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    double b,c,d;
    int a;
    b=3.14159265358979323846;

    cin>>a;
    cout.precision(20);
    c=a*b;
    c*=2;
    printf("%.20lf",c);

    return 0;

}



Measured memory_bytes: 3768
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string s;
	cin >> s;
	int n = s.length(), i, j, k, c1 = 0, c2 = 0;
	for (i = 0; i < n; i++) {
		if ((i % 2) != s[i] - '0') c1++;
		else c2++;
	}

	cout << min(c1, c2) << "\n";


	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
 
//#include <vector>
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
ll mod =  1000000007;
ll maxn = 1000000000;
 
//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pii = pair<int, int>; // これ以降 pii という型名はpair<int, int> と同じ意味で使える
//---------------------------------------------------------------------------------------------------
 
int main(){
    int n,m;
    cin>>n>>m;
    cout<<(n+m)*(n+m-1)/2 - n*m<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define all(v) v.begin(),v.end()
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }

struct Edge { ll from, to, cost; };
using EdgeList = vector<vector<Edge>>;

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

    rep(i, N - 1) {
        int s, t, w; cin >> s >> t >> w;
        E[s].emplace_back(Edge{s, t, w});
        E[t].emplace_back(Edge{t, s, w});
    }
    vector<ll> dp(N);
    function<ll(int, int)> dfs = [&] (int now, int prev) {
        dp[now] = 0;
        for(Edge &e : E[now]) {
            if(e.to == prev) continue;
            set_max(dp[now], dfs(e.to, now) + e.cost);
        }
        return dp[now];
    };
    function<ll(int, int, ll)> dfs2 = [&] (int now, int prev, ll v) {
        ll res = 0;
        using T = pair<ll, int>;
        vector<T> values = {T(0, -1)}; // ??????
        for(Edge &e : E[now]) {
            ll vv = e.to != prev ? dp[e.to] : v;
            values.emplace_back(vv + e.cost, e.to);
        }
        sort(all(values), greater<T>());
        set_max(res, values[0].first + values[1].first);
        for(Edge &e : E[now]) {
            if(e.to == prev) continue;
            ll vv = (values[0].second != e.to ? values[0] : values[1]).first;
            set_max(res, dfs2(e.to, now, vv));
        }
        return res;
    };
    dfs(0, -1);
    cout << dfs2(0, -1, 0) << endl;
    return 0;
}

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

int main(){
    long N;
    scanf("%ld", &N);
    deque<long> A(N);
    for(auto& i : A)scanf("%ld", &i);

    N >>= 1;

    deque<long> B(A);

    nth_element(begin(A), begin(A) + N - 1, end(A));
    nth_element(begin(A) + N - 1, begin(A) + N, end(A));

    for(const auto i : B)printf("%ld\n", i >= A[N] ? A[N - 1] : A[N]);

    return 0;
}

Measured memory_bytes: 5504
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    long n,m,l,i,j,k;
    cin>>n>>m>>l;
    long a[n][m],b[m][l];
    long c[n][l];
    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            c[i][j]=0;
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
    for(i=0;i<m;i++){
        for(j=0;j<l;j++){
            cin>>b[i][j];
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            for(k=0;k<m;k++){
                c[i][j]+=a[i][k]*b[k][j];
            }
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            if(j==l-1){
                cout<<c[i][j]<<endl;
            }else{
                cout<<c[i][j]<<" ";
            }
        }
    }
    return 0;
}




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

int main() {
	
  	int n;
  	cin >> n;
  	
  	int ans = 0;
  	if(n%1000 != 0) {
    	int t = n/1000;
      	ans = (t+1)*1000 - n;
    }	
  
  	cout << ans << "\n";
  
  	fflush(stdout);
	return 0;
}

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

string to_string(string s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define db(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define db(...) 42
#endif

using ll = long long;

int main() {
  ll a, b, x;
  cin >> a >> b >> x;
  cout << (b/x - a/x) + (a % x == 0) << '\n';
  return 0;
}


Measured memory_bytes: 256
while 1:
    h, w, n = map(int, raw_input().split())
    if h == 0: break
    l = [map(int, raw_input().split()) for i in range(h)]
    dp = [[0]*w for i in range(h)]
    dp[0][0] = n - 1
    for i in range(h):
        for j in range(w):
            if i + 1 < h: dp[i+1][j] += (dp[i][j] + (l[i][j] ^ 1)) >> 1
            if j + 1 < w: dp[i][j+1] += (dp[i][j] + l[i][j]) >> 1
    dx = dy = 0
    while dx < w and dy < h:
        if (dp[dy][dx] + l[dy][dx]) % 2 == 0: dy += 1
        else: dx += 1
    print dy + 1, dx + 1

Measured memory_bytes: 27092
#include <bits/stdc++.h>
using namespace std;
#define INF 1000006
#define MOD 1000000007

int n;
int mem[INF][2][2];

int rec(int pos,int zero,int nine)
{
	if(pos==n)
	{
		if(zero==1 && nine==1)
		{
			return 1;
		}
		return 0;
	}
	if(mem[pos][zero][nine]!=-1) return mem[pos][zero][nine]%MOD;
	int now=0;
	for(int i=0;i<=9;i++)
	{
		if(i==0)
		{
			now=((now%MOD)+(rec(pos+1,1,nine)%MOD))%MOD;
		}else
		if(i==9)
		{
			now=((now%MOD)+(rec(pos+1,zero,1)%MOD))%MOD;
		}else
		{
			now=((now%MOD)+(rec(pos+1,zero,nine)%MOD))%MOD;
		}
	}
	return mem[pos][zero][nine]=now%MOD;
}

int main()
{
	//freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    memset(mem,-1,sizeof(mem));
    cin >> n;
    int ans=rec(0,0,0);
    cout << ans%MOD << "\n";
}


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

l = [[a, b, c] for a, b, c in zip(A, B, C)]

cnt = 0
for i in range(N):
    l_set = set(l[i])
    if len(l_set) == 1:
        pass
    elif len(l_set) == 2:
        cnt += 1
    else:
        cnt += 2

print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int sum,max;
  max = -1;
  cin >> n;
  int a[2][n];
  for(int i = 0;i < n;i++){
    cin >> a[0][i];
  }
  for(int i = 0;i < n;i++){
    cin >> a[1][i];
  }
  for(int i = 0;i < n;i++){
    sum = 0;
    for(int j = 0;j <= i;j++){
      sum += a[0][j];
    }
    for(int j = i;j < n;j++){
      sum += a[1][j];
    }
    if(sum > max) max = sum;
  }
  cout << max << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

const int INF = 1 << 24;
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;

const int MOD = 100000007;
ll fact[2001];

ll extgcd(ll a, ll b, ll &x, ll &y){
    ll d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

ll mod_inverse(ll a, ll m){
    ll x, y;
    extgcd(a, m, x, y);
    return (m + x % m) % m;
}

ll mod_fact(ll n, ll p, ll& e){
    e = 0;
    if(n == 0){return 1;} // 0! = 1

    ll res = mod_fact(n/p, p, e);
    e += n / p;
    
    if(n/p % 2 != 0){return res * (p - fact[n%p]) % p;}
    return res * fact[n%p] % p;
}

ll mod_comb(ll n, ll k, ll p){
    if(n < 0 || k < 0 || n < k){return 0;}
    ll e1, e2, e3;
    ll a1 = mod_fact(n, p, e1), a2 = mod_fact(k, p, e2), a3 = mod_fact(n-k, p, e3);
    if(e1 > e2 + e3){return 0;}
    return a1 * mod_inverse(a2 * a3 % p, p) % p;
}

int main(){
    fact[0] = 1;
    FOR(i, 1, 2001){
        fact[i] = (fact[i-1] * i) % MOD;
    }

    int r, c, a1, a2, b1, b2;
    std::cin >> r >> c >> a1 >> a2 >> b1 >> b2;

    if(a1 > b1){std::swap(a1, b1);}
    if(a2 > b2){std::swap(a2, b2);}

    int dx[2], dy[2];
    dx[0] = b1-a1;
    dy[0] = b2-a2;
    dx[1] = a1 + r - b1;
    dy[1] = a2 + c - b2;
    
    int shortest_path = INF;

    REP(i, 2){
        REP(j, 2){
            shortest_path = std::min(shortest_path, dx[i]+dy[j]);
        }
    }

    ll res = 0;
    REP(i, 2){
        REP(j, 2){
            if(dx[i] + dy[j] == shortest_path){
                res = (res + mod_comb(dx[i]+dy[j], std::min(dx[i],dy[j]), MOD)) % MOD;
            }
        }
    }
    
    std::cout << res << std::endl;
}

Measured memory_bytes: 1176
#include <iostream>
#define REP(i,n) for (int i=0; i<n; i++)

using namespace std;

int table[11][11];
bool checked[100005];

int rete(int a, int b, int c, int d){
	int x;
	x = table[0][a];
	x = table[x][b];
	x = table[x][c];
	x = table[x][d];
	return x;
}

bool check(int a, int b, int c, int d, int e){
	// if (checked[a*10000+b*1000+c*100+d*10+e]) return false;
	// checked[a*10000+b*1000+c*100+d*10+e] = true;
	
	int x;
	x = table[0][a];
	x = table[x][b];
	x = table[x][c];
	x = table[x][d];
	x = table[x][e];
	return x==0;
}

int answer(int a, int b, int c, int d, int e){
	REP(i,10){
			if (i!=a && check(i, b, c, d, e)) return 1;
			if (i!=b && check(a, i, c, d, e)) return 1;
			if (i!=c && check(a, b, i, d, e)) return 1;
			if (i!=d && check(a, b, c, i, e)) return 1;	
			if (i!=e && check(a, b, c, d, i)) return 1;	
	}
	if (a!=b && check(b, a, c, d, e)) return 1;
	if (b!=c && check(a, c, b, d, e)) return 1;
	if (c!=d && check(a, b, d, c, e)) return 1;
	if (d!=e && check(a, b, c, e, d)) return 1;
	return 0;
}

int main(){
	int ans=0;
	REP(i,100000){
		checked[i] = false;
	}
	REP(j, 10){
		REP(k, 10){
			table[j][k] = 0;
		}
	}
	
	REP(j,10){
		REP(k,10){
			scanf("%d", &table[j][k]);
		}
	}
	
	REP(a,10){
		REP(b,10){
			REP(c,10){
				REP(d,10){
				
					int e = rete(a, b, c, d);
					check(a, b, c, d, e);
					//if (a==2) cerr << a << b << c << d << e << endl;;
					ans += answer(a, b, c, d, e);
				}
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3348
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    auto v = make_v(n, m, 0);
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < m; ++j) {
            v[i][j] = (s[j] == '1');
        }
    }
    auto s = make_v(n+1, m+1, 0);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            s[i+1][j+1] = v[i][j];
        }
    }
    for (int i = 0; i < n; ++i) for (int j = 0; j < m+1; ++j)  s[i+1][j] += s[i][j];
    for (int i = 0; i < n+1; ++i) for (int j = 0; j < m; ++j)  s[i][j+1] += s[i][j];

    auto verw = make_v(n+1, m, 0);
    auto verh = make_v(n, m+1, 0);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m-1; ++j) {
            if(v[i][j] && v[i][j+1]) verw[i+1][j+1] = 1;
        }
    }
    for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j)  verw[i+1][j] += verw[i][j];
    for (int i = 0; i < n+1; ++i) for (int j = 0; j < m-1; ++j)  verw[i][j+1] += verw[i][j];
    for (int i = 0; i < n-1; ++i) {
        for (int j = 0; j < m; ++j) {
            if(v[i][j] && v[i+1][j]) verh[i+1][j+1] = 1;
        }
    }
    for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j)  verh[i][j+1] += verh[i][j];
    for (int i = 0; i < n-1; ++i) for (int j = 0; j < m+1; ++j)  verh[i+1][j] += verh[i][j];
    while(q--){
        int x1, y1, x2, y2;
        scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
        int ans = s[x2][y2] - s[x1-1][y2] - s[x2][y1-1] + s[x1-1][y1-1];
        ans -= verh[x2-1][y2] - verh[x1-1][y2] - verh[x2-1][y1-1] + verh[x1-1][y1-1];
        ans -= verw[x2][y2-1] - verw[x1-1][y2-1] - verw[x2][y1-1] + verw[x1-1][y1-1];
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 64640
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int m, f, r;
    char grade;
    
    while(true){
        
        cin >> m >> f >> r;
        
        
        if(m == -1 && f == -1 && r == -1) break;
        else if(m == -1 || f == -1) cout << "F" << endl;
        else if(m + f >= 80) cout << "A" << endl;
        else if(m + f >= 65) cout << "B" << endl;
        else if(m + f >= 50) cout << "C" << endl;
        else if(m + f >= 30 ) cout << ((r >= 50) ? "C" : "D") << endl;
        else if(m + f >= 30) cout << "D" << endl;
        else  cout << "F" << endl;
    }
}


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

// the final position of golem whose initiali position is i
int sim(int i, string S, int N, int Q, int* dist, char td_list[][2]) {
    int idx = i;
    for (int j = 0; j < Q; ++j) {
        if (dist[i] != -2) return dist[i];
        if (idx == -1 || idx == N) {
            dist[i] = idx;
            return dist[i];
        }
        if (td_list[j][0] == S[idx]) {
            if (td_list[j][1] == 'L') idx--;
            else idx++;
        }
    }
    dist[i] = idx;
    return dist[i];
}

int main() {
    // init and load
    int N, Q;
    string S;
    cin >> N >> Q;
    cin >> S;
    char td_list[Q][2];
    for (int i = 0; i < Q; ++i) {
        cin >> td_list[i][0] >> td_list[i][1];
    }
    int dist[N];
    for (int i = 0; i < N; ++i) {
        dist[i] = -2;
    }
    // search left mergine
    int left = -1, right = N, mid;
    while (right - left != 1) {
        mid = (left + right) / 2;
        if (sim(mid, S, N, Q, dist, td_list) == -1) {
            left = mid;
        }
        else {
            right = mid;
        }
    }
    int lb = right;

    // search right margin
    left = -1, right = N;
    while (right - left != 1) {
        mid = (left + right) / 2;
        if (sim(mid, S, N, Q, dist, td_list) == N) {
            right = mid;
        }
        else {
            left = mid;
        }
    }
    int rb = left;
    cout << rb - lb + 1 << endl;
    return 0;
}

Measured memory_bytes: 1924
X,Y,Z,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

A=(sorted(A,reverse=True))[:K]
B=(sorted(B,reverse=True))[:K]

AB=[]
for Ai in A:
    for Bj in B:
        AB.append(Ai+Bj)
AB=(sorted(AB,reverse=True))[:K]

C=(sorted(C,reverse=True))[:K]

ABC=[]
for ABi in AB:
    for Cj in C:
        ABC.append(ABi+Cj)
ABC=(sorted(ABC,reverse=True))[:K]

for ABCi in ABC:
    print(ABCi)

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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)

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

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 109, M = 2e5 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;

int main(){
    init();
    int n,m,x,i,j,k;
    cin>>n>>m>>x;
    long long int c[n];
    long long int a[n][m];
    for(i=0;i<n;i++)
    {cin>>c[i];
     for(k=0;k<m;k++)
            cin>>a[i][k];
    }
    int ans = OO;
    for(i=0;i<1<<n;i++)
    {long long h[m]={0};
     int totalCost = 0;
        for(j=0;j<n;j++)
        {
            if(1&(i>>j))
            {for(k=0;k<m;k++)
              h[k]+=a[j][k];
              totalCost+=c[j];
            }
        }
        int p= 1;
        for(int k = 0;k < m;k++)
            if(h[k] < x)
            p= 0;

        if(p!=0)
            ans = min(ans, totalCost);
    }if(ans== OO)
    cout<<"-1";
    else
        cout<<ans;
    return 0;
}


Measured memory_bytes: 3648
module Main where

import Control.Applicative
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

readi b | Just (n, _) <- B.readInt b = n

main :: IO ()
main = do
    getLine
    as <- fmap readi . B.words <$> B.getLine :: IO [Int]
    let bs = take 2 . filter ((>= 2) . length)
           . group . sortBy (flip compare) $ as
    let ans = case bs of
            []   -> 0
            [xs] -> 0
            [xs, ys] | length xs >= 4 -> head xs ^ 2
                     | otherwise      -> head xs * head ys
    print ans

Measured memory_bytes: 15612
N = int(input())
import sys
nn = [0 for _ in range(10**5+3)]
for _ in range(N):
  a,b = map(int,input().split())
  nn[a] += 1
  nn[b+1] -= 1
ans = 0
sss = 1
for i in range(len(nn)):
  sss += nn[i]
  if i <= sss:
    ans = i
print(ans-1)


Measured memory_bytes: 6504
#include <stdio.h>
int n;
int Bsearch(int A[],int key){
        int left=0,right=n;
        while(left<right) {
                int mid = (left + right)/2;
                if (A[mid] == key) {
                        return 1;
                }
                if (key > A[mid]) {
                        left = mid+1;
                }
                else if(key < A[mid]) {
                        right = mid;
                }
        }
        return 0;
}
int  main(){
        int A[1000000];
        int i,q,key,sum=0;
        scanf("%d",&n);
        for(i=0; i<n; i++) {
                scanf("%d",&A[i]);
        }
        scanf("%d",&q);
        for(i=0; i<q; i++) {
                scanf("%d",&key);
                if(Bsearch(A,key)) {
                        sum++;
                }
        }
        printf("%d\n",sum);

        return 0;
}



Measured memory_bytes: 2180
n, k = map(int, input().split())
ans = 0
if k == 0:
    ans = n*n
else:
    for i in range(1, n+1):
        ans += n//i * max(i-k, 0)
        a = n//i * max(i-k, 0)
        b = 0
        if i >= k and n % i != 0:
            ans += max(0, (n%i+1)-k)
            b = max(0, (n%i+1)-k)
print(ans)


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

/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	int n;
	cin >> n;
	vector<int> s;
	vector<int> b;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		s.push_back(a);
	}
	if (s.size() % 2 == 0) {
		for (int i = s.size() - 1; i >= 0; i = i - 2) {
			cout << s[i] << " ";
		}
		for (int i = 0; i < s.size(); i = i + 2) {
			cout << s[i] << " ";
		}
	
	}
	else {
		for (int i = s.size() - 1; i >= 0; i = i - 2) {
			cout << s[i] << " ";
		}
		for (int i = 1; i < s.size(); i = i + 2) {
			cout << s[i] << " ";
		}


	}
}

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

using namespace std;

int main()
{
    while (true) {
        int n, m, a, b, c, t;
        cin >> n >> m >> a >> b >> c >> t;
        if (n == 0 && m == 0 && a == 0 && b == 0 && c == 0 && t == 0) {
            return 0;
        }
        using Vector = vector<int>;
        Vector v;
        v.reserve(n);
        for (int i = 0; i < n; ++i) {
            int x;
            cin >> x;
            v.push_back(x);
        }

        using Matrix = vector<Vector>;
        auto generateMatrix = [](size_t size) {
            return Matrix(size, Vector(size, 0));
        };
        auto binaryMatrixPower = [generateMatrix, m](const Matrix& x, int n) {
            auto matrixMultiplication = [generateMatrix, m](const Matrix& a,
                                                            const Matrix& b) {
                const auto n = a.size();
                auto c = generateMatrix(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) {
                            c[i][j] = (c[i][j] + (a[i][k] * b[k][j]) % m) % m;
                        }
                    }
                }
                return c;
            };
            auto x_ = x;
            auto result = generateMatrix(x.size());
            for (int i = 0; i < x.size(); ++i) {
                result[i][i] = 1;
            }
            while (n != 0) {
                if ((n & 1) != 0) {
                    result = matrixMultiplication(result, x_);
                    n -= 1;
                }
                x_ = matrixMultiplication(x_, x_);
                n /= 2;
            }
            return result;
        };
        auto multiplyMatrixVector = [m](const Matrix& matrix, const Vector& v) {
            Vector result(v.size(), 0);
            for (int i = 0; i < v.size(); ++i) {
                for (int j = 0; j < v.size(); ++j) {
                    result[i] = (result[i] + (matrix[i][j] * v[j]) % m) % m;
                }
            }
            return result;
        };
        auto matrix = generateMatrix(v.size());
        for (int i = 0; i < v.size(); ++i) {
            if (i - 1 >= 0) {
                matrix[i][i - 1] = a;
            }
            matrix[i][i + 0] = b;
            if (i + 1 < v.size()) {
                matrix[i][i + 1] = c;
            }
        }

        matrix = binaryMatrixPower(matrix, t);
        auto r = multiplyMatrixVector(matrix, v);
        for (int i = 0; i < v.size(); ++i) {
            if (i != 0) {
                cout << ' ';
            }
            cout << r[i];
        }
        cout << endl;
    }
}


Measured memory_bytes: 3172
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    N = int(input())

    ans = 0
    for _ in range(N):
        x, u = input().split()
        x = float(x)
        if u == "JPY":
            ans += x
        else:
            ans += x * 380000

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3948
#include <bits/stdc++.h>
#define int long long
using namespace std;
int gcd(int a, int b){
    if (b==0) return a;
    return gcd(b, a%b);
}
void solve(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a-b < 0){
        cout << "No" << endl;
        return;
    }
    if (b > d){
        cout << "No" << endl;
        return;
    }
    int g = gcd(b, d);
    int ost = a%g;
    c++;
    b--;
    if (b-c < 0){
        cout << "Yes" << endl;
        return;
    }
    if (b-c >= g-1){
        cout << "No" << endl;
        return;
    }
    int o1 = c%g, o2 = b%g;
    if (o2 >= o1){
        if (ost >= o1 && ost <= o2) cout << "No" << endl;
        else cout << "Yes" << endl;
        return;
    }
    else{
        if (ost >= o1 || ost <= o2) cout << "No" << endl;
        else cout << "Yes" << endl;
        return;
    }
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    for (int i=0; i < t; i++) solve();
    return 0;
}


Measured memory_bytes: 256
//atcoder "maze master"

#include <bits/stdc++.h>

using namespace std;
#define ll long long
/*
vector<size_t> sort_by_length(const vector<ll> &v,const vector<ll> &v1) {

  // initialize original index locations
  vector<size_t> idx(v.size());
  iota(idx.begin(), idx.end(), 0);

  // sort indexes based on comparing values in v
  // using std::stable_sort instead of std::sort
  // to avoid unnecessary index re-orderings
  // when v contains elements of equal values 
  stable_sort(idx.begin(), idx.end(),
       [&v](size_t i1, size_t i2) {return v[i1]+v1[i1] < v[i2]+v1[i2];});

  return idx;
}
*/

int main()
{
    ll n=0;
    cin>>n;
    vector<ll> x;
    vector<ll> l;
    for(int i=0;i<n;i++){
        ll input;
        cin>>input;
        x.push_back(input);
        cin>>input;
        l.push_back(input);
    }
    //vector<bool> used(n);
    //vector<size_t> idx=sort_by_length(l,x);
    vector<pair<ll,ll> > sorted;
    for (int i = 0; i < n; ++i) { 
        sorted.push_back(make_pair(x[i]+l[i], i)); 
    } 
    sort(sorted.begin(),sorted.end());
    ll maxend=LLONG_MIN;
    ll count=0;
    
    ll last=0;
    for(;;){
        //int i=sorted[ii].second;//idx[ii];
        ll minend=LLONG_MAX;
        int c=0;
        ll minL=LLONG_MAX;
        for(int jj=last;jj<n;jj++){
            int j=sorted[jj].second;//index[jj];
            ll end=x[j]+l[j];
            ll start=x[j]-l[j];
            //cout<<start<<","<<end;
            //if(start>=maxend&&(end<minend||(end==minend&&minL>l[j]))){
            if(start>=maxend){
                /*
                if(minL>l[j])
                    minL=l[j];*/
                minend=end;
                //maxend=end;
                c=1;
                last=jj;
                break;
        //        cout<<"*";
                //cout<<start<<","<<end<<endl;
            }
        //    cout<<endl;
        }
        //    cout<<endl;
        if(c>0){
            maxend=minend;
        }else{
            break;
        }
        count+=c;
    }
    cout<<count<<endl;
    //cout << dis[w - 1][h - 1];
    return 0;
}

Measured memory_bytes: 3948
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define vll vector<ll>
#define sz size()
#define pb emplace_back
#define mp make_pair
#define MOD 1000000007
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL))
const int N = 100005;

int main()
{
	ll a,b;
	cin>>a>>b;
	if(a==1 && b==1)
	cout<<"1000000";
	else if((a==1&&b==2)||(a==2 && b==1))
	cout<<"500000";
	else if((a==2 &&b==2)||(a==1&&b==3)||(a==3 &&b==1))
	cout<<"400000";
	else if((a==2 && b==3)||(a==3 && b==2))
	cout<<"300000";
	else if(a==3 &&b==3)
	cout<<"200000";
	else
	{
		if(a==1 ||b==1)
		cout<<"300000";
		else if(b==2 ||a==2)
		cout<<"200000";
		else if(a==3 ||b==3)
		cout<<"100000";
		else 
		cout<<"0";
	}
}

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

if K<(B-A)/2+1:
    for i in range(A, A+K):
        print(i)
    for i in range(B-K+1, B+1):
        print(i)
else:
    for i in range(A, B+1):
        print(i)

Measured memory_bytes: 3060
X, Y = list(map(int, input().split()))

a = Y/2 - X
b = -Y/2 + 2*X

a = round(a)
b = round(b)

flag = False
if(a >= 0 and b >=0):
    if(a + b == X and 4*a + 2*b == Y):
        flag = True

if flag:
    print('Yes')
else:
    print('No')

"""
カメ a匹，鶴b羽とすると

a + b = X

4a + 2b = Y

↓

2a = y - 2X

-2b = Y - 4X

↓

a = y/2 - X

b = -y/2 + 2X
"""

Measured memory_bytes: 9132
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n,m;
  while(cin >>n>>m,n||m){
    double fer[101][101];
    double dp[101][101] = {0};
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
	cin >>fer[i][j];
      }
    }
    for(int i=0; i<n; i++){dp[0][i] = 1;}
    for(int i=0; i<m-1; i++){
      for(int j=0; j<n; j++){
	for(int k=0; k<n; k++){
	  dp[i+1][k] = max(dp[i+1][k],dp[i][j]*fer[j][k]);
	}
      }
    }
    double ans = 0;
    for(int i=0; i<n; i++){ans = max(ans,dp[m-1][i]);}
    printf("%.2lf\n",ans);
  }
  return 0;
}

Measured memory_bytes: 1408
# AtCoder Beginner Contest 125
# https://atcoder.jp/contests/abc125
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main(A, B, T):
    n = int((T + 0.5) / A) * B
    print(n)

A, B, T = i2nn()
main(A, B, T)


Measured memory_bytes: 3064
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int M = sc.nextInt();
    PriorityQueue<Integer> A = new PriorityQueue<>(Collections.reverseOrder());

    for (int i = 0; i < N; i++) {
      A.add(sc.nextInt());
    }

    sc.close();

    while (0 < M) {
      int max = A.poll();
      max = max / 2;
      A.offer(max);
      M--;
    }

    long sum = 0;

    for (int i = 0; i < N; i++) {
      sum += A.poll();
    }

    System.out.println(sum);

  }

}

Measured memory_bytes: 58388
# AOJ 0259: All Numbers Lead to 6174
# Python3 2018.6.25 bal4u

while True:
	n = input()
	if int(n) == 0: break
	if len(set(n)) == 1:
		print("NA")
		continue
	ans = 0
	while n != "6174":
		ans += 1
		l = ''.join(sorted(n))
		s = l[::-1]
		n = str(int(s)-int(l)).zfill(4)
	print(ans)



Measured memory_bytes: 5608
S=list(input())
A=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

L=[0 for i in range(26)]

for i in range(len(S)):
    for j in range(26):
        if S[i]==A[j]:
            L[j]+=1
            
#print(L)
ans=1
num=sum(L)
for i in range(26):
    ans+=L[i]*(num-L[i])
    num-=L[i]
print(ans)

Measured memory_bytes: 61808
#include<stdio.h>
#include<string.h>

int main(void)
{
  int i,j,k,sw,e,e1,e2,i1,j1,c1,c2;
  char st1[201],st2[201],st3[201],st4[201];

  while(1)
    {
      scanf("%s",st1);
      if(st1[0]=='.' && st1[1]=='\0') break;
      scanf("%s",st2);
	  e2=0;
      c1=0;
      c2=0;
      for(i=0;i<=strlen(st1)-1;i++)
	{
	  if(st1[i]=='"') c1++;
	}
      for(i=0;i<=strlen(st2)-1;i++)
	{
	  if(st2[i]=='"') c2++;
	}
      if(c1!=c2) printf("DIFFERENT\n");
      else
	{
	  e=0;
      e1=0;
	  i=0;
	  while(st1[i]!='"' && st1[i]!='\0')
	    {
	      st3[i]=st1[i];
	      i++;
	    }
	  j=0;
	  while(st2[j]!='"' && st2[j]!='\0')
	    {
	      st4[j]=st2[j];
	      j++;
	    }
	  if(i!=j) e=1;
	  else
	    {
	      for(k=0;k<=j-1;k++)
		{
		  if(st3[k]!=st4[k]) e1++;
		}
	    }
	  if(e1!=0) e=1;
	  i1=0;
	  j1=0;
	  sw=1;
	  while(st1[i]!='\0')
	    {
	      e1=0;
	      i++;
	      j++;
	      while(st1[i]!='"' && st1[i]!='\0')
		{
		  st3[i1]=st1[i];
		  i1++;
		  i++;
		}
	      while(st2[j]!='"' && st2[j]!='\0')
		{
		  st4[j1]=st2[j];
		  j1++;
		  j++;
		}
	      if(i1!=j1)
		{
		  if(sw==1) e2++;
		  else e=1;
		}
	      else
		{
		  for(k=0;k<=i1-1;k++)
		  {
		    if(st3[k]!=st4[k]) e1++;
		  }
		  if(e1!=0)
		    {
		      if(sw==1) e2++;
		      else e=1;
		    }
		}
	      i1=0;
	      j1=0;
	      sw=-sw;
	    }
	  if(e==0 && e2==0) printf("IDENTICAL\n");
	  else if(e==1 || e2>=2) printf("DIFFERENT\n");
	  else printf("CLOSE\n");
	}
    }
  return 0;
}

Measured memory_bytes: 1684
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define PII         pair<int, int>
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

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...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    vector<int> v(3);
    int o = 0, e = 0;
    for(int i = 0; i < 3; i++){
        cin >> v[i];
        if(v[i] & 1) o++;
        else e++;
    }
    sort(ALL(v));
    if(e == 3 || o == 3){
        cout << (v[2] - v[0] + v[2] - v[1]) / 2;
    }else if(e == 2){
        for(auto &x : v){
            if(x % 2 == 0){
                x++;
            }
        }
        sort(ALL(v));
        cout << (v[2] - v[0] + v[2] - v[1]) / 2 + 1;
    }else if(o == 2){
        for(auto &x : v){
            if(x & 1){
                x++;
            }
        }
        sort(ALL(v));
        cout << (v[2] - v[0] + v[2] - v[1]) / 2 + 1;
    }
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

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

int main()
{
  int i, j, n, cnum=0;
  char s[12];
  cin >> s;
  n=strlen(s);

  for(i=2; i<n-1; i++) {
    if(s[i]=='C'){
      cnum++;
      j=i;}
  }
  for(i=1; i<j; i++)
    if(s[i]==toupper(s[i]))
      {cout << "WA";
	return 0;}
  for(i=j+1; i<n; i++)
    if(s[i]==toupper(s[i]))
      {cout << "WA";
	return 0;}
	if((s[0]=='A')&&(cnum==1))
     cout << "AC";
     else cout << "WA";
     
  
  return 0;
}


Measured memory_bytes: 256