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

using Real = long double;
using Point = complex< Real >;
const Real EPS = 1e-12, PI = acos(-1.0L);

inline bool eq(Real a, Real b) { return fabs(b - a) < EPS; }

istream &operator>>(istream &is, Point &p) {
  Real a, b;
  is >> a >> b;
  p = Point(a, b);
  return is;
}


struct Circle {
  Point p;
  Real r;

  Circle() = default;

  Circle(Point p, Real r) : p(p), r(r) {}
};

using Points = vector< Point >;
using Circles = vector< Circle >;

int checker(Circle c1, Circle c2) {
  if(c1.r < c2.r) swap(c1, c2);
  Real d = abs(c1.p - c2.p);
  if(c1.r + c2.r < d) return 4;
  if(eq(c1.r + c2.r, d)) return 3;
  if(c1.r - c2.r < d) return 2;
  if(eq(c1.r - c2.r, d)) return 1;
  return 0;
}

bool intersect(Circle c1, Circle c2) {
    int tmp = checker(c1, c2);
    return 1 <= tmp and tmp <= 3;
}


pair< Point, Point > crosspoint(const Circle &c1, const Circle &c2) {
  Real d = abs(c1.p - c2.p);
  Real a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
  Real t = atan2(c2.p.imag() - c1.p.imag(), c2.p.real() - c1.p.real());
  Point p1 = c1.p + Point(cos(t + a) * c1.r, sin(t + a) * c1.r);
  Point p2 = c1.p + Point(cos(t - a) * c1.r, sin(t - a) * c1.r);
  return {p1, p2};
}

int N, K;
Points P;
vector<int> c;
vector<long double> r;
Circles C;
void input() {
    cin >> N >> K;
    P.resize(N);
    c.resize(N);
    C.resize(N);
    r.resize(N);
    for(int i = 0; i < N; i++) {
        cin >> P[i] >> c[i];
    }
}

void solve() {
    long double ok = 1e6;
    long double ng = 0.0;
    for(int timer = 0; timer <= 40; timer++) {
        bool clear = false;
        long double mid = (ok + ng) / 2;
        for(int i = 0; i < N; i++) {
            r[i] = mid / c[i];
            C[i] = Circle(P[i], r[i]);
        }
        Points Check;
        for(int i = 0; i < N; i++) {
            Check.push_back(P[i]);
            for(int j = i + 1; j < N; j++) {
                if(intersect(C[i], C[j])) {
                    auto tmp = crosspoint(C[i], C[j]);
                    Check.push_back(tmp.first);
                    Check.push_back(tmp.second);
                }
            }
        }
        for(auto p : Check) {
            int cnt = 0;
            for(int i = 0; i < N; i++) {
                if(abs(P[i] - p) <= r[i] + EPS)  cnt++;
            }
            if(cnt >= K) clear = true;
        }
        if(clear) ok = mid;
        else ng = mid;
    }
    cout << fixed << setprecision(20) << ok << endl;
}

int main() {
    input();
    solve();
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool prime(ll n) {
  if (n == 1) {
    return false;
  } else {
    for (ll i = 2; i <= (ll)pow(n, 0.5); i++) {
      if (n%i == 0) return false;
    }
  }
  return true;
}
ll RepeatSquaring(ll n, ll p, ll m) {
  if (p == 0) return 1;
  if (p%2 == 0) {
    ll t = RepeatSquaring(n, p/2, m);
    return (t*t)%m;
  }
  return (n*RepeatSquaring(n, p-1, m))%m;
}

int main() {
  ll n, a, b, c;
  cin >> n;
  ll tmp;
  if (n == 2) {
    cin >> a >> b;
    tmp = gcd(a, b);
  } else {
    cin >> a >> b >> c;
    tmp = gcd(a, gcd(b, c));
  }
  if (tmp == 1) {
    cout << 1 << endl;
  } else {
    vector <ll> v;
    for (ll i = 1; i <= (ll)pow(tmp, 0.5); i++) {
      if (tmp%i == 0) {
        v.push_back(i);
        if (i != tmp/i) {
          v.push_back(tmp/i);
        }
      }
    }
    sort(v.begin(), v.end());
    rep(i, v.size()) {
      cout << v.at(i) << endl;
    }
  }
}


Measured memory_bytes: 3300
#include <bits/stdc++.h>
using namespace std;
#define int                     long long int
#define ld                      long double
#define pb                      push_back
#define rep(i,a,b,c)            for(int i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(int i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     3e18
#define vpii                    vector<pair<int,int>>
#define si                      set<int>
#define usi                     unordered_set<int>
#define vi                      vector<int>
#define vld                     vector<ld>
#define vvi                     vector<vector<int>>
#define vvld                    vector<vector<ld>>
#define pii                     pair<int,int>
#define vvpii                   vector<vector<pair<int,int>>>
#define pqi                     priority_queue<int>
#define mii                     map<int,int>
#define mic                     map<int,char>
#define um                      unordered_map
#define umii                    um<int,int>
#define umic                    um<int,char>
#define umci                    um<char,int>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define test                    int Testcases;cin>>Testcases;while(Testcases--)
#define input(a,n)              for(int i=0;i<n;++i) cin>>a[i];
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

void inp_out()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
    #endif
}

int32_t main()
{
	fastIO
	inp_out();
	int x;
	cin>>x;

	int amount=100,ans=0;
	while(1)
	{	
		if(amount>=x)
		{
			cout<<ans;
			return 0;
		}
		amount=amount+amount/100;
		++ans;
	}

	return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  int vert = tx - sx;
  int hort = ty - sy;
  for(int i=0;i<vert;i++) cout << "R";
  for(int i=0;i<hort;i++) cout << "U";
  for(int i=0;i<vert;i++) cout << "L";
  for(int i=0;i<hort;i++) cout << "D";
  cout << "D";
  for(int i=0;i<vert+1;i++) cout << "R";
  for(int i=0;i<hort+1;i++) cout << "U";
  cout << "LU";
  for(int i=0;i<vert+1;i++) cout << "L";
  for(int i=0;i<hort+1;i++) cout << "D";
  cout << "R" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static class node{
		int val=-1;
		node prev;
		node next;
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		String str=scn.next();
		int []arr=new int[str.length()];
		for(int i=0;i<str.length();i++) {
			arr[i]=str.charAt(i)-'0';
		}
		node start=new node();
		node ptr=new node();
		ptr=start;
		for(int i=str.length()-1;i>=0;i--) {
			if(start.val==-1) {
				node n1=new node();
				n1.val=arr[i];
				n1.prev=null;
				n1.next=null;
				start=n1;
				ptr=start;
			}else if(arr[i]==1) {
				//System.out.println(i);
				if(ptr.val==1) {
					//System.out.println("jj");
					node n1=new node();
					n1.val=arr[i];
					n1.prev=ptr;
					n1.next=null;
					ptr.next=n1;
					ptr=n1;
					
				}else {
					if(start!=null&&ptr!=start) {
						//System.out.println("mmmm");
						ptr=ptr.prev;
						ptr.next=null;
					}else if(ptr==start) {
						start=new node();
						ptr=start;
					}
				}
			}else {
				
				if(ptr.val==0){
					node n1=new node();
					n1.val=arr[i];
					n1.prev=ptr;
					n1.next=null;
					ptr.next=n1;
					ptr=n1;
				}else {
					if(start!=null&&ptr!=start) {
						//System.out.println("mmmm");
						ptr=ptr.prev;
						ptr.next=null;
					}else if(ptr==start) {
						start=new node();
						ptr=start;
					}
				}
					
				
			}
//			node n=start;
//			while(n!=null) {
//				System.out.print(n.val+" ");
//				n=n.next;
//			}
//			System.out.println("klklklklll"+i);
		}
		int cnt=0;
		while(start!=null) {
			if(start.val!=-1)
				cnt++;
			start=start.next;
			
		}
		System.out.println(str.length()-cnt);
	}

}


Measured memory_bytes: 30664
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    public void run() {
        Scanner sc = new Scanner(System.in);
        // じゃんけんの回数
        int N = sc.nextInt();
        // K回前と同じ手が出せない
        int K = sc.nextInt();
        // グーで買った点数
        int R = sc.nextInt();
        // チョキで勝った点数
        int S = sc.nextInt();
        // パーで勝った点数
        int P = sc.nextInt();
        // じゃんけん出す順
        String[] T = sc.next().split("");

        int point = 0;
        for (int i = 0; i < T.length; i++) {
            if (i < K) {
                if (T[i].equals("r")) {
                    point = point + P;
                } else if (T[i].equals("s")) {
                    point = point + R;
                } else if (T[i].equals("p")) {
                    point = point + S;
                }
            } else {
                if (T[i].equals("r")) {
                    if (T[i - K].equals("r")) {
                        T[i] = "x";
                    } else {
                        point = point + P;
                    }
                } else if (T[i].equals("s")) {
                    if (T[i - K].equals("s")) {
                        T[i] = "x";
                    } else {
                        point = point + R;
                    }
                } else if (T[i].equals("p")) {
                    if (T[i - K].equals("p")) {
                        T[i] = "x";
                    } else {
                        point = point + S;
                    }
                }
            }
        }

        System.out.println(point);
    }
}

Measured memory_bytes: 34012
#include <iostream>

using namespace std;

int main(void) {
	long long N,M;
	cin >> N >> M;
	long long res = 0;
	if (M >= 2*N) {
		res += N;
		M -= 2*N;
		res += M/4;
	}
	else {
		res += M/2;
	}
	cout << res << endl;
	return 0;
}


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

int q;

int main() {
  cin >> q;
  while (q--) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ans = 0;
    for (int yi = a; yi <= c; yi++) {
      for (int xi = b; xi <=d; xi++) {
        if (yi % 2 == 1 and xi % 2 == 0) {
        } else {
          ans++;
        }
      }
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3076
#include<iostream>

using namespace std;

int main(){
	int n, m, x;
	cin>>n>>m>>x;
	int a[100];
	int c1=0, c2;

	for (int i = 0; i < m; i++){
		cin>>a[i];
		if(a[i] < x){
			c1++;
		}
	}
	c2 = m - c1;
	if(c1 < c2){
		cout<<c1<<endl;
	}else{
		cout<<c2<<endl;
	}
return 0;
}


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

#define rep(i, a) for (int i = 0; i < (int)a; ++i)
#define REP(i, a, b) for (int i = (a); i < (int)b; ++i)

using namespace std;
using ll = long long;
using P = pair<int, int>;

void Main() {
  int n;
  cin >> n;
  ll ans = 0;
  rep(i, n) ans += i;
  cout << ans << endl;
}

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


Measured memory_bytes: 256
n,x = map(int,input().split())
m = []
count = 0
for i in range(n):
    m.append(int(input()))

if (x-sum(m)) < min(m):
    print(n)
else:
    res = x - sum(m)
    while True:
        count = count+1
        res = res - min(m)
        if res < min(m):
            print(count+n)
            break


Measured memory_bytes: 9192
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    ll n;cin>>n;
    ll a[n];
    ll sum=0;
    rep(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    ll cnt=0;
    ll ans=sum;
    rep(i,0,n){
        cnt+=a[i];
        ll t=sum-cnt;
        ans=min(ans,abs(t-cnt));
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
def main():
    s = input()
    l = ["K", "I", "H", "B", "R"]
    for i in range(len(l)):
        if l[i] not in s:
            print("NO")
            exit()

    c = 0
    ac = 0
    for i in range(len(s)):
        if c == 0:
            if s[i] == "K":
                c = 1
                ac = 0
            elif s[i] != "A":
                print("NO")
                exit()
            else:
                ac += 1
            if ac > 1:
                print("NO")
                exit()
        elif c == 1:
            if s[i] != "I":
                print("NO")
                exit()
            c = 2
        elif c == 2:
            if s[i] != "H":
                print("NO")
                exit()
            c = 3
        elif c == 3:
            if s[i] == "B":
                c = 4
                ac = 0
            elif s[i] != "A":
                print("NO")
                exit()
            else:
                ac += 1
            if ac > 1:
                print("NO")
                exit()
        elif c == 4:
            if s[i] == "R":
                c = 5
                ac = 0
            elif s[i] != "A":
                print("NO")
                exit()
            else:
                ac += 1
            if ac > 1:
                print("NO")
                exit()
        elif c == 5:
            if s[i] == "A":
                ac += 1
            else:
                print("NO")
                exit()
            if ac > 1:
                print("NO")
                exit()
    print("YES")


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import java.util.*;
import java.util.stream.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);

	static void solve() {
		int n = in.nextInt();
		int x = in.nextInt();
		int[] m = new int[n];
		int sum = 0;
		int min = 100000;
		for (int i=0; i<n; i++) {
			m[i] = in.nextInt();
			sum += m[i];
			min = Math.min(min, m[i]);
		}
		x -= sum;
		out.println((n + x / min));
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		solve();
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		in.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}

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

void calcRoad( int m[16][16], int t, int s, int x, int y )
{
    if( t == x && s == y )
        return;
    
    if( t - 1 >= 0 && m[t-1][s] != -1 )
    {
        m[t-1][s]++;
        calcRoad( m, t - 1, s, x, y );
    }

    if( s + 1 <= y && m[t][s+1] != -1 )
    {
        m[t][s+1]++;
        calcRoad( m, t, s + 1, x, y );
    }
}

int main()
{
    int a, b, n;
    int x, y;
    int m[16][16];

    while( cin >> a >> b ) 
    {
        if( a == 0 && b == 0 )
            break;
        
        cin >> n;

        for( int i = 0; i < 16; i++ )
            for( int j = 0; j < 16; j++ )
                m[i][j] = 0;

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

        calcRoad( m, b - 1 , 0, 0, a - 1 );

        cout << m[0][a-1] << endl;
    }
    return 0;
}


Measured memory_bytes: 3084
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0122

"""
import sys
from sys import stdin
from collections import namedtuple, deque
input = stdin.readline


def bfs(pyon, sprinklers):
    # ??´?????????????§????????????´????????§?¨??????????
    dy = [-2, -2, -2, -1,  0,  1, -1, 0, 1,  2, 2, 2]
    dx = [-1,  0,  1, -2, -2, -2,  2, 2, 2, -1, 0, 1]

    # ??????????????°???(S)??¨??´????????°???(G)?????????
    sx = pyon.x                   #  ??????????????°????????§?¨?
    sy = pyon.y
    num_sprinkler = len(sprinklers)
    jump = 0                    #  ?????£?????????????????°

    Q = deque()
    Q.append((sx, sy, jump))
    while Q:
        cx, cy, jump = Q.popleft()        #  ?????¨??°?????§?¨?
        if jump >= num_sprinkler:
            return 'OK'
        for i in range(len(dx)):
            nx = cx + dx[i]
            ny = cy + dy[i]
            #  ?§????????????§???????????? ?????? ??¢?????¢?´¢?????§???????????°??????????????§?????¢?´¢????¶???????
            if is_safe(sprinklers, jump, nx, ny):
                Q.append((nx, ny, jump + 1))
    return 'NA'


def is_safe(sprinklers, jump, nx, ny):
    if not 0 <= nx <= 9:
        return False
    if not 0 <= ny <= 9:
        return False
    sp_x = sprinklers[jump].x
    sp_y = sprinklers[jump].y
    if not sp_x - 1 <= nx <= sp_x + 1:
        return False
    if not sp_y - 1 <= ny <= sp_y + 1:
        return False
    return True


def can_survive(pyon, sprinklers):
    return bfs(pyon, sprinklers)


pos = namedtuple('pos', ['x', 'y'])
def main(args):
    while True:
        px, py = map(int, input().split())
        if px == 0 and py == 0:
            break
        pyon = pos(px, py)
        n = int(input())
        temp = [int(x) for x in input().split(' ')]
        sprinklers = []
        for i in range(n):
            sprinklers.append(pos(temp[i*2], temp[i*2+1]))

        result = can_survive(pyon, sprinklers)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])
    

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

#define MAXN 50000

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

	int n, i, j, k, x;
	bool valid = true;
	cin >> n;
	map<int, int> ct;
	map<int, int>::iterator it;
	for (i = 0; i < (1 << n); i++) {
		cin >> x;
		ct[x]++;
	}
	vector<int> a;
	a.push_back(ct.rbegin()->first);
	ct[a[0]]--;
	if (ct[a[0]] == 0) ct.erase(a[0]);

	for (i = 1; i <= n; i++) {
		for (j = 0; j < (1 << (i - 1)); j++) {
			it = ct.lower_bound(a[j]);
			if (it == ct.begin()) {
				valid = false; break;
			}
			it--;
			x = it->first;
			a.push_back(x);
			if (--ct[x] == 0) ct.erase(x);
		}
	}

	if (valid) cout << "Yes\n"; 
	else cout << "No\n";

	return 0;
}


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

void solve(long long N, long long M, long long C, std::vector<long long> B, std::vector<std::vector<long long>> A)
{
    long long cnt = 0;

    for (int i = 0; i < N; i++)
    {
        long long sum = 0;
        for (int j = 0; j < M; j++)
        {
            sum += A[i][j] * B[j];
        }

        if (sum + C > 0)
        {
            cnt++;
        }
    }

    cout << cnt << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    long long C;
    scanf("%lld", &C);
    std::vector<long long> B(M);
    for (int i = 0; i < M; i++)
    {
        scanf("%lld", &B[i]);
    }
    std::vector<std::vector<long long>> A(N, std::vector<long long>(M));
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < M; j++)
        {
            scanf("%lld", &A[i][j]);
        }
    }
    solve(N, M, C, std::move(B), std::move(A));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){

    string weather = "";
    int R = 0;
    
    cin >>  weather;

    int i = 0;
    while(weather[i] != '\0'){
        if (weather[i] == 'R'){
            R++;
        }
        i++;
    }

    if ((weather[0] == 'R') && (weather[2] == 'R') && (weather[1] == 'S')){
        R = 1;
    }

    cout << R << endl;
    
    return 0;
}


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

int main() {
	int w, h,ans=0,tmp;
	cin >> h >> w;
	vector<vector<char>> m(h, vector<char>(w));
	vector<vector<int>> light(h, vector<int>(w,0)),L(h,vector<int>(w,0)),R(h,vector<int>(w,0)),U(h,vector<int>(w,0)),D(h,vector<int>(w,0));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> m.at(i).at(j);
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (m.at(i).at(j) == '#') {
				L.at(i).at(j) = 0;
			}
			else if (j == 0) {
				L.at(i).at(j) = 1;
			}
			else if (j > 0) {
				L.at(i).at(j) = L.at(i).at(j - 1) + 1;
			}
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = w - 1; j > -1; j--) {
			if (m.at(i).at(j) == '#') {
				R.at(i).at(j) = 0;
			}
			else if (j == w - 1) {
				R.at(i).at(j) = 1;
			}
			else if (j < w - 1) {
				R.at(i).at(j) = R.at(i).at(j + 1) + 1;
			}
		}
	}
	for (int i = 0; i < w; i++) {
		for (int j = 0; j < h; j++) {
			if (m.at(j).at(i) == '#') {
				D.at(j).at(i) = 0;
			}
			else if (j == 0) {
				D.at(j).at(i) = 1;
			}
			else if (j > 0) {
				D.at(j).at(i) = D.at(j - 1).at(i) + 1;
			}
		}
	}
	for (int i = 0; i < w; i++) {
		for (int j = h - 1; j > -1; j--) {
			if (m.at(j).at(i) == '#') {
				U.at(j).at(i) = 0;
			}
			else if (j == h - 1) {
				U.at(j).at(i) = 1;
			}
			else if (j < h - 1) {
				U.at(j).at(i) = U.at(j + 1).at(i) + 1;
			}
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			tmp = L.at(i).at(j) + R.at(i).at(j) + U.at(i).at(j) + D.at(i).at(j) - 3;
			if (tmp > ans) {
				ans = tmp;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 85872
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);

        int n, m, l;

        n = scanner.nextInt();
        m = scanner.nextInt();
        l = scanner.nextInt();

        int[][] a = new int[n][m];
        int[][] b = new int[m][l];
        long[][] c = new long[n][l];

        //create A matrix
        for(int arow = 0; arow < n; arow++){
            for(int acol = 0; acol < m; acol++){
                a[arow][acol] = scanner.nextInt();
            }
        }

        //create B matrix
        for(int brow = 0; brow < m; brow++){
            for(int bcol = 0; bcol < l; bcol++){
                b[brow][bcol] = scanner.nextInt();
            }
        }

        for(int ccol = 0; ccol < l; ccol++){
            for(int arow = 0; arow < n; arow++){

                for(int acol = 0; acol < m; acol++){
                    c[arow][ccol] += a[arow][acol] * b[acol][ccol];
                }
            }
        }


        for(int row = 0; row < n; row++){
            for(int col = 0; col < l-1; col++){
                System.out.print(c[row][col] + " ");
            }
            System.out.println(c[row][l-1]);
        }

        scanner.close();
    }
}



Measured memory_bytes: 52248
#include "bits/stdc++.h"
#define MOD 1000000007
#define inf 0x3f3f3f3f3f3f3f3f
#define pi acos(-1.0)
#define ri register int
#define int long long
#define P pair<char, char>
#ifdef ONLINE_JUDGE
const int maxn = 3e5 + 10;
#else
const int maxn = 1e3 + 10;
#endif
using namespace std;
string s, t;
signed main()
{
    ios::sync_with_stdio(false);
    cin >> s >> t;
    set<char> st;
    int N = s.size();
    for (ri i = 0; i < N; ++i) {
        if (s[i] == t[i]) {
            continue;
        }
        if (st.count(s[i]) || st.count(t[i])) {
            return cout << "No" << endl, 0;
        }
        st.insert(t[i]);
        char a = s[i], b = t[i];
        for (ri j = i; j < N; ++j) {
            if (s[j] == a) {
                s[j] = b;
            } else if (s[j] == b) {
                s[j] = a;
            }
        }
       // cout << s << endl;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 916
//wherever you are,whatever you do, be in love

#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

ll a[1000002];
int main(){
	ll n,flag=0,g;
	cin>>n;
	set<ll> s;
	forn(i,n){
		cin>>a[i];
		if(i==0) g=a[i];
		else g=__gcd(g,a[i]);
	}
	forn(i,n){
		ll te=a[i];
		for(ll j=2;j<=sqrt(te);j++){
			if(te%j!=0) continue;
			while(te%j==0) te/=j;
	
				auto it=s.find(j);
				if(it!=s.end()){
					flag=1;
					break;
				}
				s.insert(j);
		}
		if(te!=1){
		auto it=s.find(te);
		if(it!=s.end()){
			flag=1;
			break;
		}
		s.insert(te);
		}
		if(flag==1) break;
		//if(a[i]!=1) s.insert(a[i]);
	}
	if(flag!=1) cout<<"pairwise coprime";
	else if(g==1) cout<<"setwise coprime";
	else cout<<"not coprime";
	cout<<endl;
}

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

int main() {
  string S;
  cin >> S;
  vector<string> day;
  day = {"MON", "TUE", "WED", "THU", "FRI", "SAT"};
  for (int i = 0; i < 6; i++){
    if(S == "SUN") {
      cout << 7 << endl;
      break;
    }
    
    if(S == day[i]) cout << 6-i << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include <iostream>
#include<string.h>     
#include<algorithm>
#define ll long long
#define hengheng main ()
int i,j,n,m,k,sum,count;
int a[10000],b[10000];int flag; 
using namespace std;
int hengheng
{
	while(scanf("%d",&n)!=EOF)
	{
		flag=0;
		a[1]=n;
		for(i=2; ;i++)
		{
			if(a[i-1]%2==0) a[i]=a[i-1]/2;
			else 
			a[i]=a[i-1]*3+1;
			if(flag==1)
				break;
			for(j=1;j<=i;j++)
			{
				 flag=0;
				for(k=j+1;k<=i;k++)
				{
					if(a[j]==a[k])
					{
						sum=k;
						printf("%d\n",sum);
						flag=1;
						break;
					}
				}
				if(flag==1)
				break;
			}
			
		}
		
	}
	
	return 0;
}

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

int main()
{
  bool ans = 1;
  string s, t;
  cin >> s >> t;
  map<char, int> s_words, t_words;
  vector<int> s_vec, t_vec;
  for (int i = 0, w_s = (int)s.size(); i < w_s; ++i)
  {
    if (s_words.count(s[i]))
      ++s_words[s[i]];
    else
    {
      s_words[s[i]] = 1;
    }
  }
  for (int i = 0, w_s = (int)t.size(); i < w_s; ++i)
  {
    if (t_words.count(t[i]))
      ++t_words[t[i]];
    else
    {
      t_words[t[i]] = 1;
    }
  }
  for (auto _s = s_words.begin(), _t = t_words.begin(); _s != s_words.end() and _t != t_words.end();++_s, ++_t)
  {
	s_vec.push_back(_s->second);
    t_vec.push_back(_t->second);
  }
  if (s_vec.size() != t_vec.size()) {
    cout << "No\n";
    return 0;
  }
  sort(s_vec.begin(), s_vec.end());
  sort(t_vec.begin(), t_vec.end());
  for (size_t i = 0; i < s_vec.size(); ++i) 
  {
    if (s_vec[i] != t_vec[i]) {
      ans = 0;
      break;
    }
  }

  if (ans)
    cout << "Yes\n";
  else
    cout << "No\n";
}

Measured memory_bytes: 776
n = int(input())
alist = list(map(int,input().split()))
i_roop = 1
while i_roop > 0 :
  alist.sort()
  n = len(alist)  
  k = min(alist)
  if k == sum(alist) :
    break
  else:
    for j in range(1,n):
      alist[j] = alist[j] % k
  
  alist = [i for i in alist if not i  == 0]  
print(alist[0])

Measured memory_bytes: 14252
#include <stdio.h>
#include <algorithm>

#define minn(a,b) (a<=b?a:b)
#define maxx(a,b) (a>=b?a:b)

typedef long long ll;
const int INF=0x3f3f3f3f;
const ll INFLL=0x3f3f3f3f3f3f3f3f;

int t1,t2,t3,t4;
long long l1,l2,l3,l4;

int n;
int a[200005];
long long ps[200005];

long long ans=INFLL;

void stuff(int i,int j,int k)
{
    // [0,i) [i,j) [j,k) [k,n)
    if (0>=i) return;
    if (i>=j) return;
    if (j>=k) return;
    if (k>=n) return;
    l1=l2=ps[i];
    l1=minn(l1,ps[j]-ps[i]);
    l1=minn(l1,ps[k]-ps[j]);
    l1=minn(l1,ps[n]-ps[k]);
    l2=maxx(l2,ps[j]-ps[i]);
    l2=maxx(l2,ps[k]-ps[j]);
    l2=maxx(l2,ps[n]-ps[k]);
    //printf("%d %d %d = %lld\n",i,j,k,l2-l1);
    ans=minn(ans,l2-l1);
}

int main()
{
    #ifdef NOT_DMOJ
    freopen("data.txt","r",stdin);
    #endif // NOT_DMOJ
    scanf("%d",&n);
    ps[0]=0;
    for (int i=0; i<n; i++) {
        scanf("%d",a+i);
        ps[i+1]=ps[i]+a[i];
    }
    for (int t2=2; t2<=n-2; t2++) {
        // have subsequences [0,i) and [i,n)
        // want to split these evenly
        t1=std::lower_bound(ps,ps+t2,ps[t2]/2)-ps;
        t3=std::lower_bound(ps+t2,ps+n,(ps[n]+ps[t2])/2)-ps;
        for (int i=-2; i<=2; i++) {
            for (int j=-2; j<=2; j++) {
                stuff(t1+i,t2,t3+j);
            }
        }
    }
    printf("%lld\n",ans);
}


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

int main(){
  int n,k;
  cin >> n >> k;
  long long tmp = n/k;
  long long ans = tmp*tmp*tmp;

  long long c = 0;
  if(k%2 == 0){
    for(int i = k/2;i <= n;i+=k){
      c++;
    }
  }
  ans += c*c*c;
  cout << ans << endl;


  return 0;
}


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

int main()
{
/*********************/
// Author:
        Arman_Sykot;
/*********************/
    
    string s, t;
    cin >> s >> t;

    int ans = t.size();
    for (int i = 0; i <= s.size() - t.size(); i++) {
        int count = 0;
        for (int j = 0; j < t.size(); j++) {
            if (t[j] != s[i + j])
                count++;
        }

        ans = min(ans, count);
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 3528
#!/usr/bin/ruby
class Fixnum
	def pow_binary_mod(y)
		x = self
		z = 1
		while y != 0
			while y % 2 == 0
				x = x * x % $N
				#y = y / 2
				y = y >> 1
			end
			y = y - 1
			z = z * x % $N
		end
		z
	end
	def +(n)
		(self.to_f+n.to_f).to_i%$N
	end
	def -(n)
		(self.to_f-n.to_f+$N).to_i%$N
	end
	def *(n)
		(self.to_f*n.to_f).to_i%$N
	end
	def /(n)
		raise if n==0
		self*n.pow_binary_mod($N-2)%$N
	end
end
loop{
	n,exp=gets.chomp.gsub(' ','').split(':')
	$N=n.to_i
	break if $N==0
	begin
		puts "#{exp} = #{eval(exp)} (mod #{$N})"
	rescue
		puts :NG
	end
}

Measured memory_bytes: 11140
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#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(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pf push_front
#define pb push_back
#define P pair<int,int>
#define Pll pair<ll,ll>

template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<"\n";}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18;
const long MOD =1e+9+7;
#define PI 3.14159265258979

int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

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

	int N;
	char c;
	deque<char> S;

	cin>>N;
	REP(i,N){
		cin>>c; S.pb(c);
	}

	int	result=0;
	REP(i,S.size()) //末尾に')'を入れる個数を求める
		if(S[i]=='(') result++; 
		else result=max(0,result-1);
	
	REP(i,result) S.pb(')');

	result=0;
	REP(i,S.size()) //先頭に'('を入れる個数を求める
		if(S[i]==')') result++; 
		else result--;
	
	REP(i,result) S.pf('(');

	
	for(auto itr:S) printf("%c",itr);
	print();
	return 0;
}




Measured memory_bytes: 256
#include <stdio.h>
#define max_S 10
#define Max(a, b) a > b ? a : b
void initArray(char a[], int length);
int retlen(char a[]);
int check(char c);

int main(void)
{
    char a[max_S];
    initArray(a, max_S);
    char c = 'G';
    gets(a);
    int len = retlen(a);
    int max = 0, i = 0;
    while (i < len)
    {
        int tmp = 0;
        if (check(a[i]) == 0)
        {
            while (check(a[i]) == 0)
            {
                tmp++;
                i++;
            }
            max = Max(tmp, max);
        }
        else
        {
            i++;
        }
    }
    printf("%d\n",max);
    return 0;
}

void initArray(char a[], int length)
{
    for (int i = 0; i < length; i++)
    {
        a[i] = 0;
    }
}

int retlen(char a[])
{
    int i = 0;
    while (a[i] != 0)
    {
        i++;
    }
    return i;
}

int check(char c)
{
    return (c - 'A') * (c - 'T') * (c - 'G') * (c - 'C');
}

Measured memory_bytes: 128
n,a,b=map(int,input().split())
s=input()
ab=a+b
now=0
nowb=0
for i in range(n):
    if s[i]=="a":
        if now<ab:
            print("Yes")
            now+=1
        else:
            print("No")
    elif s[i]=="b":
        nowb+=1
        if nowb<=b and now<ab:
            print("Yes")
            now+=1
        else:
            print("No")
    else:
        print("No")

Measured memory_bytes: 53080
#include<stdio.h>
int main(void){
        int a,b,r,d;
        double f;
        scanf("%d %d",&a,&b);
        d = a / b;
        r = a % b;
        f = (double)a/(double)b;
        printf("%d %d %lf\n",d,r,f);

        return 0;
}

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

int main(){
    int n;
    cin >> n;
    int a, b;
    int x = 0;
    int y = 0;
    for (int i = 0; i < n; i++){
        cin >> a >> b;
        if (a > x) x = a, y = b;
    }
    cout << x + y << endl;
}

Measured memory_bytes: 256
s = input()
k = int(input())
substrings = []
index = []
for ss in sorted(list(set(s))):
  index_list = [n for n, v in enumerate(s) if v == ss]
  for i in index_list:##初期位置
    for j in range(1,min(k+1,len(s)-i+1)):##長さ
      substrings.append(s[i:i+j])
  if len(set(substrings)) >= k:
    break
print(sorted(list(set(substrings)))[k-1])

Measured memory_bytes: 4568
import sys
input=sys.stdin.readline
#グラフの連結成分を調べる
def Graph(ab):
    G=[[] for i in range(n)]
    for a,b in ab:
        G[a-1].append(b)
        G[b-1].append(a)
    return G
from collections import deque
def dfs(G,v,p,n):
    q=deque()
    q.append((v,p,1,0))
    log=[0]*n
    log[v-1]=1
    ans=0
    while q:
        V,P,cnt,S=q.pop()
        if S==0:
            #下に遷移していくときの処理
            q.append((V,P,cnt,1))
            for new_v in G[V-1]:
                if new_v==P:continue
                if log[new_v-1]:continue
                log[V-1]=1
                #print(V, new_v, cnt, q, log)
                if cnt==n-1:
                    ans+=1
                    continue
                q.append((new_v,V,cnt+1,0))

        else:
            log[V-1]=0
    return ans

n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(m)]
G=Graph(ab)
#print(G)
ans=dfs(G,1,-1,n)
print(ans)

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N;
  cin >> N;
  ll k=0;
  FOR(i,1, N+1){
    if(i*(i+1)>=2*N){
      k=i;
      break;
    }
  }
  FOR(i, 1, k+1){
    if(i==(k*(k+1)/2 - N))continue;
    cout << i << endl;
  }
  return 0;
}


Measured memory_bytes: 3596
#include<stdio.h>
int main(){
  int x,y,n,r;
  scanf("%d %d",&x,&y);
  if(x<y){
    n=x;
    x=y;
    y=n;
  }
  while(y>0){
  r=x%y;
  x=y;
  y=r;
  }
  printf("%d",x);
  printf("\n");
  return 0;
}
    



Measured memory_bytes: 2104
import java.util.Arrays;
import java.util.Scanner;

class B {
    public static void main(String... args) {
        final Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        final int K = sc.nextInt();
        final int[] h = new int[N];
        for (int i = 0; i < N; i++)
            h[i] = sc.nextInt();
        final int[] dp = new int[N];
        Arrays.setAll(dp, i -> i > 0 ? Integer.MAX_VALUE : 0);
        for (int i = 0; i < N; i++)
            for (int j = 1; j <= K && i + j < N; j++)
                dp[i + j] = Math.min(dp[i + j], dp[i] + Math.abs(h[i + j] - h[i]));
        System.out.println(dp[N - 1]);
    }
}
public class Main {
    public static void main(String... args) {
        B.main();
    }
}


Measured memory_bytes: 51040
#include<stdio.h>
#include<string.h>
#include<math.h>
#include <stdlib.h>
#include<ctype.h>


int main() {
	
	int R;
	scanf("%d",&R);
	
	float answer = R*2*3.1415;
	printf("%f",answer);
	
	return 0;
}

Measured memory_bytes: 1748
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define int long long
#define inf (int)1e18 + 7

int n, a[404];
int dp[404][404];

int solve(int beg, int fin) {

  if (beg == fin) {
    return 0;
  }
  int &res = dp[beg][fin];
  if (res != -1) return res;
  res = inf;
  int sum = 0;
  for (int i = beg; i < fin; i ++) {
    sum += a[i];
    res = min(res, solve(beg, i) + solve(i + 1, fin));
  } sum += a[fin];
  res += sum;
  return res;
}

signed main() {
  cin >> n;
  for (int i = 0; i < n; i ++) {
    cin >> a[i];
  }
  memset(dp, -1, sizeof dp);
  int res = solve(0, n - 1);
  cout << res << endl;

  return 0;
}

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	long long c[n-1],s[n-1],f[n-1];
	for (int i = 0; i < n-1; ++i)
	{
		cin>>c[i]>>s[i]>>f[i];
	}
	long long ans[n]={};
	for (int i = 0; i < n; ++i)
	{
		for (int j = i; j < n-1; ++j)
		{
			if (ans[i]<=s[j])
			{
				ans[i]=s[j]+c[j];
			}
			else
			{
				if (ans[i]%f[j]==0)
				{
					ans[i]+=c[j];
				}
				else
				{
					ans[i]-=ans[i]%f[j];
					ans[i]+=c[j]+f[j];
				}
			}
		}
	}
	for (int i = 0; i < n; ++i)
	{
		cout<<ans[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
import itertools
import math
N = int(input())

lst = []

for i in range(N):
    l = list(map(int, input().split()))
    lst.append(l)

D = list(itertools.permutations(lst))
ans = 0

for one_set in D:
    for j in range(len(one_set)-1):
        ans += math.sqrt((one_set[j][0] - one_set[j+1][0])**2 +((one_set[j][1] - one_set[j+1][1])**2))

print(ans/len(D))

Measured memory_bytes: 7972
#include <bits/stdc++.h>
#define  rep(i,n) for(li i = 0; i < (n); ++i)
#define  red(i,n) for(li i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a) 
using namespace std;
using li = long long;
using ul = unsigned long long;
using vi = vector<li>;
using vs = vector<string>;
inline ul gcd(ul a,ul b) { return b?gcd(b,a%b):a; }
const int INF=1000000009;


int main()
{
    map<string,int> a;
    int n,m,q=0;
    string s;
    cin>>n;
    rep(i,n)cin>>s,a[s]++;
    cin>>m;
    rep(i,m)cin>>s,a[s]--;
    for(auto x:a) q=max(q,x.second);
    cout<<q<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const double INF = 1e9;
int N, a[20];
double dp[2][150001];
int main(){

  fill_n( *dp, 2 * 150001, INF);

  cin >> N;
  for(int i = 0; i < N; ++i){
    cin >> a[i];
  }
  for(int i = 1; i < 150001; ++i){
    dp[0][i] = fabs(a[0] - i) / a[0];
  }
  for(int i = 0; i < N - 1; ++i){
    for(int j = 1; j < 150001; ++j){
      if(dp[i&1][j] != INF){
        for(int k = j; k < 150001; k += j){
          dp[(i + 1)&1][k] = min( dp[(i + 1)&1][k], max( dp[i&1][j], fabs( a[i + 1] - k) / a[i + 1]));
        }
      }
      dp[i&1][j] = 1e9;
    }
  }
  double ret = INF;
  for(int i = 0; i < 150001; ++i) ret = min( ret, dp[(N - 1)&1][i]);
  cout << fixed << setprecision(10) << ret << endl;
}

Measured memory_bytes: 3580
r, c = map(int, input().split())

a = []
b = []

for i in range(r):
    a.append(list(map(int, input().split())))
    a[i].append(sum(a[i]))

for i in range(c + 1):
    total = 0
    for j in range(r):
        total += a[j][i]
    b.append(total)

a.append(b)

for i in range(r + 1):
    print(*a[i])



Measured memory_bytes: 6228
#!/usr/bin/env python3

def main():
    N, K = map(int, input().split())
    def Base_10_to_n(X, n):
        if (int(X/n)):
            return Base_10_to_n(int(X/n), n)+str(X%n)
        return str(X%n)
    print(len(Base_10_to_n(N, K)))
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
import math

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

s = int(input())

x = s // 3
ans = 0
for xi in range(1, x+1):
    tmp = s - xi*3
    ans += comb(tmp+xi-1, xi-1)
    ans %= 1000000007
print(ans)


Measured memory_bytes: 9160
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            System.out.println((N % 10 == 9 || (N / 10) % 10 == 9) ? "Yes" : "No");
        }
    }
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int a, b;
    while(cin >> a >> b)
    {
        int ans = a + b;
        ans = ans / 2;
        cout << ans << "\n";
    }
    return 0 ;
}



Measured memory_bytes: 3192
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int a[110];
int main(){ _;
  int n;cin>>n;
  REP(i,n)cin>>a[i];
  int ans=0;
  int cnt=0, id=-1;
  REP(i,n){
    if(id!=a[i]){
      cnt=1;id=a[i];
    }else{
      cnt++;
      if(cnt%2==0)ans++;
    }
  }
  cout<<ans<<endl;
}


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

int main(){
  int n,m,x;
  cin >> n >> m >> x;
  int a[m];
  rep(i,m)cin >> a[i];
  int prev=0;
  int ahead=0;
  rep(i,m){
    if(a[i]<x)prev++;
    else ahead++;
  }
  cout << min(prev,ahead) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int t[100002];
int dp[100002];
int N,L;
int rec(int x){
  if(dp[x]!=0)return dp[x];
  if(t[x-1]<t[x]&&t[x]>t[x+1])dp[x]=L-t[x];
  else if(t[x-1]<t[x]&&t[x]<t[x+1])dp[x]=rec(x+1)+L-t[x];
  else if(t[x-1]>t[x]&&t[x]>t[x+1])dp[x]=rec(x-1)+L-t[x];
  else dp[x]=max(rec(x-1),rec(x+1))+L-t[x];
  return dp[x];
}
int main(){
  cin>>N>>L;
  for(int i=1;i<=N;i++)cin>>t[i];
  t[0]=t[N+1]=0;
  int ans=0;
  for(int i=1;i<=N;i++)ans=max(ans,rec(i));
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3116
/**************************
*                         *
*  Nothing Is Impossible  *
*                         *
**************************/
#include <algorithm>
#include <iostream>
#include <fstream>
#include <ctype.h>
#include <string>
#include <vector>
#include <thread>
#include <math.h>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <set>
#include <map>
#define GetRand(Min, Max) ((rand()%(int)(((Max) + 1)-(Min))) + (Min))
#define Rep(i, min, max) for(long long i = min; i < max; ++i)
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef long double ld;
using namespace std;

void Solve(){
	int n;	cin >> n;
	if(n >= 1000){
		if(n % 1000 == 0){
			cout << 0 << endl;
			return;
		}
		cout << (1000-(n % 1000)) << endl;
	}else{
		cout << (1000-n) << endl;
	}
}

int main(){
	ios::sync_with_stdio(NULL);
	cin.tie(NULL); cout.tie(NULL);
	int t = 1;
	//int t;	cin >> t;
	while(t--) Solve();
	return 0;
}


Measured memory_bytes: 3632