akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
using namespace std;
int main () {
  int H;
  cin >> H;
  int A[H+1];
  for (int i=1; i<H+1; i++) {
    cin >> A[i];
  }
  int P[H+1], L[H+1], R[H+1];
  for (int i=1; i<H+1; i++) {
    P[i] = i/2;
    L[i] = 2*i;
    R[i] = 2*i+1;
    if (P[i]>0) {
      if (L[i]<H+1) {
	if (R[i]<H+1) {
	  cout << "node " << i << ": key = " << A[i] << ", parent key = "<< A[P[i]] << ", left key = " << A[L[i]] << ", right key = " << A[R[i]] << ", " << endl;
	}
	else {
	  cout << "node " << i << ": key = " << A[i] << ", parent key = "<< A[P[i]] << ", left key = " << A[L[i]] << ", " << endl;
	}
      }
      else {
	cout << "node " << i << ": key = " << A[i] << ", parent key = "<< A[P[i]] << ", " << endl;
      }
    }
    else if (L[i]<H+1) {
	if (R[i]<H+1) {
	  cout << "node " << i << ": key = " << A[i] << ", left key = " << A[L[i]] << ", right key = " << A[R[i]] << ", " << endl;
	}
	else {
	  cout << "node " << i << ": key = " << A[i] << ", left key = " << A[L[i]] << ", " << endl;
	}
    }
    else {
      cout << "node " << i << ": key = " << A[i] << ", " << endl;
    }
  }
}
  

Measured memory_bytes: 1164
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#define MAXN 56555
#define inf 0x3f3f3f3f
#define ll long long
using namespace std;

int n,m;
bool is_prime[MAXN];
int primer[60];
int main(){
    m=0;    
    for(int i=3;i<MAXN;++i){
        bool flag=true;
        for(int j=2;j*j<=i;++j){
            if(i%j==0){
                flag=false;
                break;
            }
        }
        if(flag&&i%5==1){
            primer[m++]=i;
        }
        if(m>=60){
            break;
        }
    }
    while(~scanf("%d",&n)){
        for(int i=0;i<n-1;++i){
            printf("%d ",primer[i]);
        }
        printf("%d\n",primer[n-1]);
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <utility>
#include <memory>
#include <valarray>
#include <climits>

using namespace std;

using ll = long long int;

#define loop(i, N) for (int i = 0; i < N; ++i)
#define scanInt(x) int x; scanf("%d", &x); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &x); getchar();
#define scanVecInt(A, N) vector<int> A(N); loop(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); loop(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(N);
    // vector<int> x(N);
    int min_xy = INT_MAX;
    int max_xy = 0;
    int min_greater_xy = INT_MAX;
    int max_less_xy = 0;
    multimap<int, int> blue_less;
    vector<int> y(N);
    loop(i, N){
        scanInt(xi);
        scanInt(yi);
        if (!(xi <= yi)) swap(xi, yi);
        // xi <= yi
        blue_less.emplace(xi, i);
        // x[i] = xi;
        y[i] = yi;
        min_xy = min(min_xy, xi);
        max_xy = max(max_xy, yi);
        min_greater_xy = min(min_greater_xy, yi);
        max_less_xy = max(max_less_xy, xi);
    }
    int min_sub = min(max_xy - min_greater_xy, max_less_xy - min_xy);
    set<int> blue_greater;
    loop(i, N - 1){
        blue_greater.emplace(y[blue_less.begin()->second]);
        blue_less.erase(blue_less.begin());
        min_sub = min(min_sub,
                      max(blue_less.rbegin()->first, *(blue_greater.rbegin())) - min(blue_less.begin()->first, *(blue_greater.begin())));
    }
    printf("%lld\n", min((static_cast<ll>(max_xy) - min_greater_xy) * (max_less_xy - min_xy),
                         (static_cast<ll>(max_xy) - min_xy) * min_sub));
}


Measured memory_bytes: 10368
/*
Original problem: https://atcoder.jp/contests/dp/tasks/dp_u
Author: sammochen
*/

#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;

#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)

#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;

const ll mod = 1e9+7;

namespace SOLVE {
	int MSB(ll x) {
		RREP(i,31,0) {
			if (x & (1 << i)) {
				return i;
			}
		}
		return -1;
	}

    void main() {
    	int n;
    	cin >> n;
    	vector<VLL> score(n, VLL(n));

    	REP(i, 0, n) {
    		REP(j, 0, n) {
    			cin >> score[i][j];
    		}
    	}		

		VLL group(1 << n); // useful to store values of groups together
    	VLL dp(1 << n); // stores the best score, allowing subsplits
    	group[0] = 0; // a group of 0 is 0
		dp[0] = 0; // a group of 0 is 0

    	REP(i, 1, 1 << n) {
			// first, find what it would be in one group
			int msb = MSB(i);
			group[i] = group[i ^ (1 << msb)];
			REP(rest, 0, msb) {
				if (i & (1 << rest)) {
					group[i] += score[msb][rest];
				}
			}

			// dp[i] is now at least this size
			dp[i] = group[i];
			// try all possible splits 
			for (int submask=i; submask != 0; submask = (submask - 1) & i) {
				dp[i] = max(dp[i], dp[submask] + dp[i ^ submask]);
			}
    	}

    	ll ans = dp[(1 << n) - 1];
    	cout << ans << endl;
    }
}


signed main() {
	int t;
	t = 1;
	// cin >> t;
	while (t--) {
		SOLVE::main();
	}

	return 0;
}

Measured memory_bytes: 1408
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

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

func main() {
	sc.Split(bufio.ScanWords)
	str := readString()
	str += ""

	n := len(str)
	max := 0
	for i := 0; i < n; i++ {
		count := countACGT(str[:i+1])

		if count > max {
			max = count
		}
	}
	fmt.Println(max)
}

func countACGT(str string) int {
	count := 0
	maxCount := 0
	for _, s := range str {
		if s == 'A' || s == 'C' || s == 'G' || s == 'T' {
			count++
			if count > maxCount {
				maxCount = count
			}
		} else {
			count = 0
		}
	}
	return maxCount
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
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; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int 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;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
int main(){
  int a;  cin>>a;
  cout<< a+a*a+a*a*a<<endl;
  return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  string s;
  cin>>s;
  ll c1=0,c2=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='0')c1++;
    else c2++;
  }
  cout<<min(c1,c2)*2<<endl;
  return 0;
}

Measured memory_bytes: 512
N = gets.to_i

require 'prime'

@ps = (1 .. N).inject(:*).prime_division.map(&:last)
f = ->x {@ps.count{|p| p >= x - 1}}
c = ->(a, b) {(a - b + 1 .. a).inject(:*) / (1 .. b).inject(:*)}
puts f[75] + f[25]*(f[3] - 1) + f[15]*(f[5] - 1) + c[f[5], 2]*(f[3] - 2)

Measured memory_bytes: 2172
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 998244353;
const ll MAX = 2000001;

ll mod(ll a){
  if(a % MOD < 0) return MOD + (a % MOD);
  return a % MOD;
}

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


int main(){
  ll a,b; cin >> a >> b;
  
  if(a % 3 == 0 or b % 3 == 0 or (a+b) % 3 == 0){
    cout << "Possible" << endl;
  }
  else cout << "Impossible" << endl;
  
  
}

Measured memory_bytes: 3640
N = int(input())
a = list(map(int,input().split()))
b = [0]*N
for i in range(N):
    ai = a[i]
    cnt = 0
    while ai > 1:
        if ai %2 == 1:
            break
        else:
            ai=ai//2
            cnt += 1
    b[i] = (cnt,a[i])
b.sort()
c=[0]*(N)
for i in range(N):
    if i%2 == 0:
        c[i] = b[i][1]
    else:
        c[i] = b[N-i][1]
for i in range(N-1):
    if c[i]*c[i+1]%4 !=0:
        print("No")
        exit()
    else:
        continue
print("Yes")


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

int main(){
    int min = 0; int max = 0;
    int N;
    bool rate[8];
    int godCoder = 0;
    cin >> N;
    int a[N-1];

    for(int i=0; i<8; ++i){
        rate[i] = false;
    }

    for(int i=0; i<N; ++i){
        cin >> a[i];
        if(a[i] < 400){ rate[0] = true; }
        else if(400 <= a[i] && a[i] <= 799){ rate[1] = true; }
        else if(800 <= a[i] && a[i] <= 1199){ rate[2] = true; }
        else if(1200 <= a[i] && a[i] <= 1599){ rate[3] = true; }
        else if(1600 <= a[i] && a[i] <= 1999){ rate[4] = true; }
        else if(2000 <= a[i] && a[i] <= 2399){ rate[5] = true; }
        else if(2400 <= a[i] && a[i] <= 2799){ rate[6] = true; }
        else if(2800 <= a[i] && a[i] <= 3199){ rate[7] = true; }
        else{ ++godCoder; }
    }

    for(int i=0; i<8; ++i){
        if(rate[i]){ ++min; ++max; }
    }
    max += godCoder;
    if(min == 0){ ++min; }
    cout << min << " " << max << endl;
}


Measured memory_bytes: 256
alp = ["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"]
dic = {}
for i in range(len(alp)):
    dic[alp[i]]=i#A->0

N = int(input())
S = list(input())

s = ""

for i in range(len(S)):
    num = (int(dic[S[i]])+N)%26
    s+=alp[num]
    
print(s)


Measured memory_bytes: 3064
import heapq


class Edge:
    def __init__(self, dst, weight):
        self.dst, self.weight = dst, weight

    def __lt__(self, e):
        return self.weight > e.weight


class Graph:
    def __init__(self, V):
        self.V = V
        self.E = [[] for _ in range(V)]

    def add_edge(self, src, dst, weight):
        self.E[src].append(Edge(dst, weight))


class Node:
    def __init__(self, v, cost):
        self.v, self.cost = v, cost

    def __lt__(self, n):
        return self.cost < n.cost


class ShortestPath:
    """Dijkstra's algorithm : find the shortest path from a vertex
       Complexity: O(E + log(V))
       used in GRL1A(AOJ)
    """

    def __init__(self, G, INF=10**9):
        """ V: the number of vertexes
            E: adjacency list (all edge in E must be 0 or positive)
            start: start vertex
            INF: Infinity distance
        """
        self.G, self.INF = G, INF

    def dijkstra(self, start, goal=None):
        que = list()
        self.dist = [self.INF] * self.G.V  # distance from start
        self.prev = [-1] * self.G.V  # prev vertex of shortest path
        self.dist[start] = 0
        heapq.heappush(que, Node(start, 0))

        while len(que) > 0:
            n = heapq.heappop(que)
            if self.dist[n.v] < n.cost:
                continue
            if goal is not None and n.v == goal:
                return
            for e in self.G.E[n.v]:
                if self.dist[n.v] + e.weight < self.dist[e.dst]:
                    self.dist[e.dst] = self.dist[n.v] + e.weight
                    heapq.heappush(que, Node(e.dst, self.dist[e.dst]))
                    self.prev[e.dst] = n.v

    def getPath(self, end):
        path = [end]
        while self.prev[end] != -1:
            end = self.prev[end]
        return path[::-1]

V, E, start = map(int, input().split())
G = Graph(V)
for _ in range(E):
    s, t, d = map(int, input().split())
    G.add_edge(s, t, d)
INF = 10**9
sp = ShortestPath(G, INF)
sp.dijkstra(start)
for i in range(G.V):
    print("INF" if sp.dist[i] == INF else sp.dist[i])

Measured memory_bytes: 150640
#include<stdio.h>

int main(){
  int n, a, b;
  
  scanf("%d", &n);
  
  if(n == 1){
    printf("Hello World\n");
  } else {
    scanf("%d %d", &a, &b);
    
    printf("%d\n", a + b);
  }
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl;
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<int>& a,int n);

int n;



bool IsPrime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2){
        if (num % i == 0){
            return false;
        }
    }
    return true;
}

signed main(){
    cin >> n;
    int ans = 0;
    REP(i,n){
        int m;
        cin >> m;
        if(IsPrime(m)) ans++;
    }
    print(ans);
    


    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<int>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}



Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

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

int INF = 1001001001;
int h, w, K;

int dfs(int cnt, int incl, vector<int> group, vector<vector<int>> is) {
    if (incl == h - 1) {
        group.push_back(h);
        int prev = 0;
        bool pos = true;
        for (int j = 1; j < w + 1; ++j) {
            rep(k, group.size() - 1) {
                if (is[group[k + 1]][j] - is[group[k]][j] - is[group[k + 1]][prev] + is[group[k]][prev] > K) {
                    cnt++;
                    prev = j - 1;
                }
                if (is[group[k + 1]][j] - is[group[k]][j] - is[group[k + 1]][j - 1] + is[group[k]][j - 1] > K) {
                    pos = false;
                    break;
                }
            }
        }
        if (!pos) return INF;
        return cnt;
    }

    incl++;
    int ret;
    ret = dfs(cnt, incl, group, is);
    group.push_back(incl);
    ret = min(ret, dfs(cnt + 1, incl, group, is));
    return ret;
}

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

    cin>>h>>w>>K;
    vector<string> ss(h);
    rep(i, h) cin>>ss[i];

    vector<vector<int>> is(h + 1, vector<int>(w + 1));
    rep(i, h) {
        rep(j, w) {
            is[i + 1][j + 1] = is[i][j + 1] + is[i + 1][j] - is[i][j];
            if (ss[i][j] == '1') is[i + 1][j + 1]++;
        }
    }

    vector<int> group;
    group.push_back(0);
    int ans = dfs(0, 0, group, is);
    cout<<ans<<endl;
}

Measured memory_bytes: 816
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


def main():
    n = intin()

    count = 0

    for i in range(1, n + 1):
        divs = get_divisors(i)
        divs = set(divs)
        if i % 2 and len(divs) == 8:
            count += 1

    print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3540
from collections import deque

H, W = map(int, input().split())

count = 0
g = []
g.append(['#'] * (W + 2))
for _ in range(H):
    lst = ['#'] + list(input()) + ['#']
    count += lst.count('.')
    g.append(lst)

g.append(['#'] * (W + 2))
check = [[-1] * (W + 2) for _ in range(H + 2)]

move = [[1, 0], [-1, 0], [0, 1], [0, -1]]


# for G in g:
#     print (G)
x = 1
y = 1
que = deque()
que.append([x, y])
# stack = [[x, y]]
flag = True
check[1][1] = 1
while que:
    tmp = que.popleft()
    x = tmp[0]
    y = tmp[1]
    # print (x, y)
    for dx, dy in move:
        nx = x + dx
        ny = y + dy
        # print (nx, ny)
        if g[nx][ny] == '.' and check[nx][ny] == -1:
            check[nx][ny] = check[x][y] + 1
            que.append([nx, ny])
            # print ('OK')

# for c in check:
#     print (c)

if check[H][W] == -1:
    print (-1)
    exit()

print (count - check[H][W])

Measured memory_bytes: 3316
N = gets.to_i
A = Array.new(N + 1, 0)
gets.split.map(&:to_i).each_with_index{|a,i| A[i + 1] = a }

R = Array.new(N + 1, 0)
(2 .. N).each do |i|
  R[i] = A[i - 1] - R[i - 1]
end
r = (A[N] - R[N]) / 2
ans = (1 .. N).map do |i|
  if i.odd?
    (R[i] + r) * 2
  else
    (R[i] - r) * 2
  end
end
puts ans * ' '


Measured memory_bytes: 14844
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps DBL_EPSILON
#define mod (ll)998244353
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, x[100010], y[100010];
char d[100010];
long double func(long double time) {
	long double mi = 200000000, ma = -200000000;
	rep(i, n) {
		if (d[i] == 'R') {
			mi = min(mi, x[i] + time);
			ma = max(ma, x[i] + time);
		}
		else if (d[i] == 'L') {
			mi = min(mi, x[i] - time);
			ma = max(ma, x[i] - time);
		}
		else {
			mi = min(mi, (long double)x[i]);
			ma = max(ma, (long double)x[i]);
		}
	}
	long double memo = ma - mi;
	mi = 200000000; ma = -200000000;
	rep(i, n) {
		if (d[i] == 'U') {
			mi = min(mi, y[i] + time);
			ma = max(ma, y[i] + time);
		}
		else if (d[i] == 'D') {
			mi = min(mi, y[i] - time);
			ma = max(ma, y[i] - time);
		}
		else {
			mi = min(mi, (long double)y[i]);
			ma = max(ma, (long double)y[i]);
		}
	}
	return memo * (ma - mi);
}
signed main() {
	cin >> n;
	rep(i, n)cin >> x[i] >> y[i] >> d[i];
	long double ok = 0, ng = 300000000;
	rep(i, 500) {
		long double md1 = ok + (ng - ok) / 3, md2 = ok + (ng - ok) * 2 / 3;
		if (func(md1) <= func(md2))ng = md2;
		else ok = md1;
	}
	printf("%.12Lf\n", func(ng));
	return 0;
}

Measured memory_bytes: 1920
n = gets.chomp.to_i
a = gets.chomp.split(' ').map(&:to_i)

def f(n, a) 
  b = []
  
  n.times do |i|
    b = b.push(a[i]).reverse
  end

  puts b.map(&:to_s).join(' ')
end

def g1(n, a)
  b = []
  m = n / 2

  (0...m).each do |i|
    b.unshift(a[2 * i + 1])
    b.push(a[2 * i])
  end
  
  return b
end

def g2(n, a)
  b = []
  m = n / 2

  (0...m).each do |i|
    b.unshift(a[2 * i])
    b.push(a[2 * i + 1])
  end
  
  b.unshift(a[n - 1])
  
  return b
end

if (n % 2) == 0 then
  puts g1(n, a).map(&:to_s).join(' ')
else
  puts g2(n, a).map(&:to_s).join(' ')
end

Measured memory_bytes: 33004
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
using ll = long long;
const int mod = 1e+9+7;

ll f(ll n) {
  if (n==1) return 1;
  return n * f(n-1) % mod;
}

int main() {
  ll ans=0;
  int n,m; cin >> n >> m;
  if (abs(n-m) > 1) { cout << 0 << endl; return 0; }

  ans = f(n) * f(m) % mod;
  if (n==m) ans*=2;

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


Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
"""
Contents   : AtCoder Grand Contest 023
Author     : Kitaura Hiromi
LastUpdate : 20180502
Since      : 20180428
"""
N = int(input())
A = list(map(int, input().split(" ")))

# O(NlogN)
S = []
tmp = 0
for i in range(N):
    S.append(tmp)
    tmp += A[i]
S.append(tmp)
S = sorted(S)
cnt = 1
ret = 0
tmp = S[0]
for i in range(1, len(S)):
    if tmp == S[i]:
        cnt += 1
    else:
        ret += cnt * (cnt - 1) // 2
        cnt = 1
        tmp = S[i]
ret += cnt * (cnt - 1) // 2
print(ret)

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

int main(){
    string S;
    cin >> S;
    int N=S.size();
    vector<int> ans(N);
    for(int i=1; i<N; i++){
        if(S[i-1]=='R' && S[i]=='L'){
            int cntL=0, cntR=0;
            int l=i, r=i-1;
            while(S[r]=='R' && r>=0){
                cntR++;
                r--;
            }
            while(S[l]=='L' && l<N){
                cntL++;
                l++;
            }
            int cnt=cntL+cntR;
            ans[i-1]=cnt/2;
            ans[i]=cnt/2;
            if(cnt%2!=0&&cntR%2==1){
                ans[i-1]++;
            }
            if(cnt%2!=0&&cntL%2==1){
                ans[i]++;
            }
        }
    }
    for(int i=0; i<N-1; i++){
        cout << ans[i] << " ";
    }
    cout << ans[N-1] << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <queue>
#include<iomanip>
#include <cmath>
#include <set>

#define ABS(x) ((x)>0?(x):-(x))
#define MIN(x,y) ((x)>(y)?(y):(x))

using namespace std;
typedef long long ll;

ll newton(long long int a, long long int  b)
{
	if(a==b)
		return a;
	while(a != 0 && b != 0)
	{
		if(a > b)
		{
			b += a;
			a = b-a;
			b -= a;
		}
		b %= a;
	}
	return a;
}

struct UnionFind {
	vector<int> p;
	UnionFind(int N):p(N)
	{
		for(int i=0; i< N; i++)
		{
			p[i] = i;
		}
	}
	int root(int x)
	{
		if(p[x] == x)
			return x;
		return p[x] = root(p[x]);
	}
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		p[rx] = ry;
	}
	bool issame(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

//大きな数に対する割り算をするとき、MODを指定することで掛け算の値に変換できる

ll div2mul_calc(ll a, ll b, ll m)
{
	if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll d = div2mul_calc(a, b / 2, m);
        return (d * d) % m;
    } else {
        return (a * div2mul_calc(a, b - 1, m)) % m;
    }
}
ll div2mul(ll n, ll mod)
{
	return div2mul_calc(n, mod-2, mod);
}

int main()
{
	int N,K;
	int V[128];
	int i,j,k,l,r;
	int a,b,total=0;
	int ans = 0;
	priority_queue<int> q;
	cin >> N >> K;
	for(i=0;i<N;++i)
	{
		cin >> V[i];
	}
	for(i=0;i<=K;++i)
	{
		//jは取得回数
		for(j=0;j<=i; ++j)
		{
			//戻せる個数
			k = K-j;
			if(j<N)
			{
				for(l=0;l<=j;++l)
				{
					while(!q.empty())
					{
						q.pop();
					}
					total=0;
					r = j - l;
					for(a=0;a<l;++a)
					{
						total += V[a];
						if(V[a] < 0)
						{
							q.push(-V[a]);
						}
					}
					for(a=0;a<r;++a)
					{
						total += V[N-1-a];
						if(V[N-1-a] < 0)
						{
							q.push(-V[N-1-a]);
						}
					}
					for(a=0;a<k;++a)
					{
						if(!q.empty())
						{
							b = q.top();
							q.pop();
							total += b;
						}
						else
						{
							break;
						}
					}
					if(total > ans)
						ans = total;
				}
			}
			else if(j==N)
			{
				//itidosubetetoru
				while(!q.empty())
				{
					q.pop();
				}
				total = 0;
				for(a=0;a<N;++a)
				{
					total += V[a];
					if(V[a] < 0)
					{
						q.push(-V[a]);
					}
				}
				k = K-j;
				for(a=0;a<k;++a)
				{
					if(!q.empty())
					{
						b = q.top();
						q.pop();
						total += b;
					}
					else
					{
						break;
					}
				}
				if(total > ans)
					ans = total;
			}
			else
			{
				break;
			}
		}
	}
	cout << ans << endl;

	/*
	int N,Q;
	int s,t,x;
	int i,j,k;
	priority_queue<pair<int, int> > q_s,q_e;

	cin >> N >> Q;
	for(i=0; i< N ; ++i)
	{
		cin >> s >> t >> x;
		s -= x;
		t -= x;
		if(s < 0)
			s = 0;
		if(t < 0)
			t = 0;
		q_s.push(make_pair(-s,x));
		q_e.push(make_pair(-t,x));
	}
	int kouji = 0;
	int ans = -1;
	for(i=0;i < Q; ++ i)
	{
		ans = -1;
		cin >> s;
		while(!q_s.empty())
		{
			if(-q_s.top().first =< s)
			{
				kouji ++;

			}
			else
		}
		while(!q_e.empty())
		{

		}
	}
	*/
	return 0;
}




































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

int main() {
    int h, w;
    scanf("%d %d ", &h, &w);
    vector<vector<char>> a(h, vector<char>(w));
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            scanf(" %c ", &a[i][j]);
        }
    }
    vector<vector<int>> dp(h, vector<int>(w, 0));
    dp[0][0] = 1;
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            if (i==0 && j==0) continue;
            if (a[i][j] == '#') continue;
            if (i!=0) dp[i][j] += dp[i-1][j];
            if (j!=0) dp[i][j] += dp[i][j-1];
            while (dp[i][j]>=MOD) dp[i][j] -= MOD;
        }
    }

    printf("%d\n", dp[h-1][w-1]);
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define F first
#define S second
#define ll long long
#define N 200010
using namespace std;
ll n,k;
double p,sum[N],ans=0;
int main(){
	ll i,j;
	double x;
	cin>>n>>k;
	memset(sum,0,sizeof(sum));
	for(i=0;i<n;i++)
	{
		cin>>x;
		p=(x+1)/2;
		sum[i+1]=sum[i]+p;
	}
	for(i=0;i+k<=n;i++)
	{
		ans=max(ans,sum[i+k]-sum[i]);
	}
	printf("%.15f\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#coding: UTF-8
import sys
N=int(input())
Say=input()
A1='SS'
A2='WS'
A3='SW'
A4='WW'
def Nextone(a,b,w):
    if w=='o':
        if a=='S' and b=='S':
            return 'S'
        elif a=='W' and b=='S':
            return 'W'
        elif a=='S' and b=='W':
            return 'W'
        else:
            return 'S'
    else:
        if a=='S' and b=='S':
            return 'W'
        elif a=='W' and b=='S':
            return 'S'
        elif a=='S' and b=='W':
            return 'S'
        else:
            return 'W'

for i in range(0,N):
    A1+=Nextone(A1[i],A1[i+1],Say[i])
    A2+=Nextone(A2[i],A2[i+1],Say[i])
    A3+=Nextone(A3[i],A3[i+1],Say[i])
    A4+=Nextone(A4[i],A4[i+1],Say[i])
if A1[1]==A1[N+1] and A1[0]==A1[N]:
    print(A1[1:N+1])
elif A2[1]==A2[N+1] and A2[0]==A2[N]:
    print(A2[1:N+1])
elif A3[1]==A3[N+1] and A3[0]==A3[N]:
    print(A3[1:N+1])
elif A4[1]==A4[N+1] and A4[0]==A4[N]:
    print(A4[1:N+1])
else:
    print(-1)

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string cad,c,d;
    while(cin>>cad){
        int a,b;
        c = cad.substr(0,2);
        d = cad.substr(2,3);
        a = atoi(c.c_str());
        b = atoi(d.c_str());

        if(1<=a && a<=12 && (b>12||b==0)){
            cout<<"MMYY"<<endl;
        }else if(1<=b && b<=12 && (a>12||a==0)){
            cout<<"YYMM"<<endl;
        }else if(1<=a && a<=12 && 1<=b && b<=12){
            cout<<"AMBIGUOUS"<<endl;
        }else{
            cout<<"NA"<<endl;
        }
    }

    return 0;
 
}

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

typedef long double ld;

int main()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
	ll n;
	cin>>n;
	ll arr[n];
	map <ll,ll> mp;
	ll su = 0;
	for(ll i=0;i<n;i++)
	{
		cin>>arr[i];
		mp[arr[i]]++;
	}
	
	for(auto it : mp)
	{
		su += it.second * (it.second-1);
	}
	
	for(ll i=0;i<n;i++)
	{
		cout<<(su-2*max(0LL,mp[arr[i]]-1))/2<<endl;
	}
	
	
}


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

int check(int p, std::vector<long long int> &w, int n, int k) {
    int index = 0;
    for (int i = 0; i < k; i++) {
        long long int sum = 0;
        while (sum + w[index] <= p) {
            sum += w[index];
            index++;
            if (index == n) return n;
        }
    }

    return index;
}

int main(int argc, char const *argv[]) {
    int n, k;
    std::cin >> n >> k;

    std::vector<long long int> w(n);
    for (int i = 0; i < n; i++) {
        std::cin >> w[i];
    }

    long long int min = 0;
    long long int max = 100000 * 10000;
    long long int mid;

    while (max - min > 1) {
        mid = min + (max - min) / 2;
        if (check(mid, w, n, k) >= n) max = mid;
        else min = mid;
    }

    std::cout << max << std::endl;

    return 0;
}

Measured memory_bytes: 1796
#include <iostream>
#include <iomanip>
using namespace std;
 
int main() {
	int h,w;
  	while(true){
    	cin>>h>>w;
      	if(h==0 && w==0) break;
      	for(int i=1;i<=h;i++){
        	for(int j=1;j<=w;j++){
          		cout<<'#'; 
            }
          cout<<endl;
        }
     	cout<<endl; 
    }
}



Measured memory_bytes: 3104
N = int(input())
MOD = 10**9 + 7
C = list(map(int, input().split()))
C.sort()

ans = 0
for i, c in enumerate(C, start=1):
    M = N - i
    ans += c * (M + 2)
    ans %= MOD
ans *= pow(4, N - 1, MOD)
print(ans % MOD)


Measured memory_bytes: 27108
#include<bits/stdc++.h>
using namespace std;
main()
{
    long long n,c,a;
    while(scanf("%lld %lld",&n,&a)==2){
        c=0;
        while(n>0){
            n/=a;
            c++;
        }
        cout<<c<<'\n';
    }
}


Measured memory_bytes: 256
#!/usr/bin/env python3
n, *a = map(int, open(0).read().split())
c = 1
d = [1] * n
a = [a[0]] + [a[i] for i in range(1, n) if a[i - 1] != a[i]]
for i in range(2, len(a)):
    if (a[i] - a[i - 1]) * (a[i - 1] - a[i - 2]) < 0 and d[i - 1]:
        c += 1
        d[i] = 0
print(c)


Measured memory_bytes: 19996
flag = 1

def search(num, digit, res, op):
    global flag
    if digit == 4:
        if res == 7:
            op += "="
            ans = "".join(n+o for n,o in zip(num, op))
            if flag:
                print(ans + "7")
                flag = 0

    else:
        search(num, digit+1, res+int(num[digit]), op+"+")
        search(num, digit+1, res-int(num[digit]), op+"-")
        
num = input()
search(num,1,int(num)//1000,"")

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  string s;
  cin >> s;
  if(s[0] == '7' || s[1] == '7' || s[2] == '7'){
    cout << "Yes\n";
  }else{
    cout << "No\n";
  }
  return 0;
}



Measured memory_bytes: 3536
#pragma warning(disable:4996)
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>
#include <stdio.h>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 998244353;
const long long INF = 1e15;
typedef long long LL;
typedef long double LD;
//typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PI;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef unsigned long long ULL;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int H, W,K;
	cin >> H >> W >> K;
	vector<vector<bool>> map;   //黒->true
	map.resize(H, vector<bool>(W, false));
	for (int y = 0; y < H; y++) {
		string S; 
		cin >> S;
		for (int x = 0; x < W; x++) {
			if (S[x] == '#')map[y][x] = true;
		}
	}
	int ans = 0;
	vector<vector<bool>> red;
	red.resize(H, vector<bool>(W, false));
	for (int cy = 0; cy < (1 << H); cy++) {
		for (int cx = 0; cx < (1 << W); cx++) {
			for (int x = 0; x < W; x++) {
				for (int y = 0; y < H; y++)red[y][x] = false;
			}
			for (int x = 0; x < W; x++) {
				if (((cx>>x)&1) == 1) {
					for (int y = 0; y < H; y++)red[y][x] = true;
				}
			}
			for (int y = 0; y < H; y++) {
				if (((cy >> y) & 1) == 1) {
					for (int x = 0; x < W; x++)red[y][x] = true;
				}
			}
			int temp = 0;
			for (int x = 0; x < W; x++) {
				for (int y = 0; y < H; y++) {
					if (map[y][x] && !red[y][x])temp++;
				}
			}
			if (temp == K)ans++;
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3196
X = int(input())
if 400 <= X <= 599:
    print('8')
elif 600 <= X <= 799:
    print('7')
elif 800 <= X <= 999:
    print('6')
elif 1000 <= X <= 1199:
    print('5')
elif 1200 <= X <= 1399:
    print('4')
elif 1400 <= X <= 1599:
    print('3')
elif 1600 <= X <= 1799:
    print('2')
elif 1800 <= X <= 1999:
    print('1')


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

using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
// end of Template

int ans;
int n,d;
double x[20][20];
bool good (int a, int b){
    double dist = 0;
    for(int i=1;i<=d;i++){
        dist += (x[a][i] - x[b][i])*(x[a][i] - x[b][i]);
    }
    dist = sqrt (dist);

    if(dist == trunc(dist))return true;
    else return false;
}
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>d;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=d;j++)cin>>x[i][j];
    }
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(good(i,j)){ans++;}
        }
    }
    cout<<ans<<newl;

}


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

int main() {
  int n,W;
  cin>>n>>W;
  vector<ll> w(n+1),val(n+1);
  for(int i = 0; i<n;i++) {
    cin>>w[i+1]>>val[i+1];
  }
  //choices are to take ith el or not
  //dp[i][w] is the max val till ith el
  // with w weight remaining
  //ans is max element of dp[n-1][i]
  ll a,b;
 // printf("here\n");
  vector<vector<ll>>dp(n+1,vector<ll>(W+1));
  for(int i = 1;i<=n;i++) {
    for(int m = 0; m<=W;m++) {
      a = 0,b= 0;
      if(m >= w[i]) {
        a = val[i] + dp[i-1][m-w[i]];
      }
      b = dp[i-1][m];
      dp[i][m] = max(a,b);
     // printf("dp[%d][%d] = %lld\n",i,m,dp[i][m]);
    }
  }
  ll res = *max_element(dp[n].begin(),dp[n].end());
  cout<<res<<endl;

}

Measured memory_bytes: 80256
/* MaTb3aa */
#include<bits/stdc++.h>
#define ll long long
using namespace std;

int n,bag;
const int N = 100005;
ll dp[105][100005];
int W[N], C[N];
ll solve(int i,int rem) {
	if (i == n)return 0;
	ll& ret = dp[i][rem];
	if (~ret)return ret;
	ret = max(ret, solve(i + 1, rem));
	if(rem>=W[i])ret = max(ret, solve(i + 1, rem - W[i]) + C[i]);
	return ret;
}
int main() {
	cin >> n>>bag;
	for (int i = 0; i < n; i++)cin >> W[i] >> C[i];
	memset(dp, -1, sizeof dp);
	cout << solve(0, bag);	 
}

Measured memory_bytes: 82432
#include<stdio.h>
#define N 100000
int A[N],n;
int partition(int p,int r){
    int x,i,j,tmp;
    x=A[r];
    i=p-1;
    for(j=p;j<r;j++){
        if(A[j] <= x){
            i++;
            tmp=A[i]; A[i]=A[j]; A[j]=tmp;
        }
    }
    tmp=A[i+1]; A[i+1]=A[r]; A[r]=tmp;
    return i+1;
}
int main(){
    int i,p;
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&A[i]);
    p=partition(0,n-1);
    for(i=0;i<n;i++){
        if(i) printf(" ");
        if(i==p) printf("[%d]",A[i]);
        else printf("%d",A[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 3008
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <random>
#include <cassert>
#include <numeric>
#define ll long long int
#define LL unsigned long long
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;

ll y[10000005];

int main() {
    ll n,p; cin >> n >> p;

    vector<ll> a;
    vector<ll> b;
    ll cnt = 0;
    while(p%2==0){
        cnt++;
        p /= 2ll;
    }
    a.pb(cnt);
    b.pb(2);

    for(ll i = 3; i * i <= p; i+=2) {
        cnt = 0;
        if (p % i == 0) {
            while (p % i == 0) {
                cnt++;
                p /= i;
            }
            a.pb(cnt);
            b.pb(i);
        }else continue;
    }
    if(p != 1) {
        a.pb(1);
        b.pb(p);
    }

    ll ans = 1;
    int s = a.size();
    rep(i,s){
        if(a[i]/n){
            ans *= pow(b[i],a[i]/n);
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 3852
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long a,b,ans=1;
  cin >> a >> b;
  long long gcd=__gcd(a,b),tmp;
  tmp=gcd;
  for(long long i=2;i<=gcd;i++){
    if(i*i>tmp){
      if(tmp>1) ans++;
      break;
    }
    if(tmp%i==0) ans++;
    while(tmp%i==0){
      tmp/=i;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.StringTokenizer;

class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int N=sc.nextInt();
		int[] alpha=new int[26];
		Arrays.fill(alpha,0);
		String[] moji=new String[3];
		for(int i=0; i<3; i++) {
			moji[i]=sc.next();
		}
		int ans=0;
		for(int i=0; i<N; i++) {
			Arrays.fill(alpha,0);
			int max=0;	//一番かぶっているもの
			for(int j=0; j<3; j++) {
				alpha[moji[j].charAt(i)-97]++;
			}
			for(int j=0; j<26; j++) {
				max=Math.max(max, alpha[j]);
			}
			ans+=(3-max);
		}
		pl(ans);
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}

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

int n,m,q;
vector<int> a,b,c,d;
int ans;

void dfs(vector<int> A){
    if(A.size()==n+1){
        int now=0;
        rep(i,q) {
            if(A[b[i]] - A[a[i]] == c[i]) now+=d[i];
        }
        ans=max(ans,now);
        return;
    }
    A.push_back(A.back());
    while (A.back() <= m){
        dfs(A);
        A.back()++;
    }
}

int main() {
    cin >> n >> m >> q;
    a = b = c = d = vector<int>(q);
    rep(i,q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    dfs(vector<int>(1,1));
    cout << ans << endl;
}

Measured memory_bytes: 3636
--AOJ Print a Frame

import Control.Applicative

rInt :: String -> Int
rInt str = read str :: Int

strFrame :: Int -> Int -> String
strFrame h w = replicate w '#'  ++ "\n"
               ++ concat (replicate (h - 2) ("#" ++ replicate (w - 2) '.' ++ "#\n"))
               ++ replicate w '#' ++ "\n"
               ++ "\n" 

main :: IO ()
main = do
  xs <- pure (map rInt . words) <*> getLine
  let h = head xs 
      w = last xs      
  if h == 0 && w == 0
    then return ()
    else do
    putStr $ strFrame h w
    main

Measured memory_bytes: 4088
from collections import deque


def bfs(adj, s, t, use):
    if s == t:
        return 1
    que = deque()
    seen = [0] * len(adj)
    que.append(s)
    seen[s] = 1
    while que:
        v = que.popleft()
        for u, cost in adj[v]:
            if seen[u] == 0 and use[cost] == 1:
                if u == t:
                    return 1
                seen[u] = 1
                que.append(u)
    return 0


N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

adj = [[] for _ in range(51)]
for i in range(51):
    for j in range(1, i+1):
        adj[i].append((i%j, j))

use = [1] * 51
use[0] = 0
for i in range(50, 0, -1):
    use[i] = 0
    for ai, bi in zip(a, b):
        if not bfs(adj, ai, bi, use):
            use[i] = 1
            break

if sum(use) == 50:
    print(-1)
    exit()

print(sum([(2**i) * use[i] for i in range(51)]))


Measured memory_bytes: 42460