akhauriyash/Code-Regression huggingface dataset:
/*  -*- coding: utf-8 -*-
 *
 * a.cc: AtCoder Group Contest
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_N * 3];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  int n3 = n * 3;
  for (int i = 0; i < n3; i++) scanf("%d", &as[i]);
  sort(as, as + n3);

  ll sum = 0;
  for (int i = 0; i < n; i++) sum += as[n3 - 2 - i * 2];
  printf("%lld\n", sum);
  return 0;
}


Measured memory_bytes: 1408
#ifdef BUILT_LOCAL

#include "niklib.h"

#endif

#include <iostream>
#include <utility>
#include <numeric>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cstring>
#include <map>
#include <cmath>
#include <set>
#include <list>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
constexpr ll mod = 1000000007;

#define bs(n) (1ll<<(ll)(n))
#define rep(i, n) for(ll (i) = 0;(i) < (n);(i)++)
#define rrep(i, n) for(ll (i) = 1;(i) <= (n);(i)++)

int main() {
    int n, m, x, c[13], a[13][13];
    cin >> n >> m >> x;
    rep(i, n) {
        cin >> c[i];
        rep(j, m) cin >> a[i][j];
    }
    int mc = 100000000;
    for (ull i = 0; i < (1ULL << (unsigned) n); i++) {
        int r[13] = {0}, cc = 0;
        rep(j, n) {
            if (i & (1ULL << (unsigned) j)) {
                cc += c[j];
                rep(k, m) {
                    r[k] += a[j][k];
                }
            }
        }
        bool ok = true;
        rep(j,m) {
            if(r[j] < x) ok = false;
        }
        if(ok) mc = min(mc,cc);
    }
    cout << (mc == 100000000 ? -1 : mc) << endl;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    vector<int> ans(n);
    rep(i,n) ans[a[i]-1] = i+1;
    
    rep(i,n) cout << ans[i] << ' ';
    cout << endl;

    return 0;
}

Measured memory_bytes: 1664
from collections import deque
mod=10**9+7
H,W = map(int,input().split())
Gd = [list(input()) for _ in range(H)]
INF = 0
direc = [[1,0],[0,1]]
def dfs(start):
  Dis = [[INF]*W for _ in range(H)]
  Dis[start[0]][start[1]]=1
  q = deque([])# スタック
  q.append(start)
  while len(q)!=0:
    h,w = q.popleft()# スタック取りだし（先頭）
    for d in direc:
      hs, ws = h + d[0], w + d[1]
      if not (0<=hs<H and 0<=ws<W):
        continue
      if Gd[hs][ws]=='.':
        if Dis[hs][ws]==INF:
          q.append([hs,ws])
        Dis[hs][ws] = (Dis[hs][ws] + Dis[h][w])%mod
  return Dis[H-1][W-1]
print(dfs([0,0]))

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


int main()
{
  ll a;
  string b;
  cin >> a >> b;
  ll ib = 0;
  int count = 0;
  bool chk = false;
  for (char& c : b)
  {
    if (c == '.')
    {
      chk = true;
      continue;
    }
    ib *= 10;
    ib += c - '0';
    if (chk)
      count++;
  }
  ll ans = a * ib;
  rep(i, count)
    ans /= 10;
  cout << ans << endl;
}

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

signed main() {
	int k,a,b,cnt=1;;
	bool bou=false;
	cin>>k>>a>>b;
	if(a+2>b){
		cout<<k+1<<endl;
		return 0;
	}
	for(int i=0;i<k;i++){
		if(bou){
			cnt+=b;
			bou=false;
		}
		else if(cnt<a||k-i+1<=2){
			cnt++;
		}
		else{
			bou=true;
			cnt-=a;
		}
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 256
void main()
{
    int n = readln.chomp.to!int;
    int[] l = readln.split.to!(int[]);

    l.sort!"a < b";
    int total;
    foreach (i; 0 .. n)
    {
        total += l[2*i];
    }

    total.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    vector<ll> l(n + 1, 0), r(n + 1, 0);
    for (int i = 0; i < n; i++) {
        l[i + 1] = l[i] + a[i];
        r[n - i - 1] = r[n - i] + a[n - i - 1];
    }
    ll ans = linf;
    for (int i = 1; i < n; i++) {
        ans = min(ans, abs(l[i] - r[i]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4224
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main(void)
{
    int faces_num;
    int goal;
    int former_border;
    double possibility;

    cin >> faces_num >> goal;

    possibility = 0;


    int i = faces_num;
    int j = goal;
    int twice_times = 0;
    if(faces_num >= goal){
        possibility += (double)(faces_num - goal + 1);
        i = goal - 1;
    }

    while(true){
        if(j <= i){
            possibility += (double)(i - j + 1) / pow(2, twice_times);
            i = j - 1;
        }

        if(j == 1){
            break;
        }
        j = ceil((double)j / 2);
        twice_times += 1;
    }

    possibility /= faces_num;

    cout << fixed;
    cout << setprecision(12) << possibility << endl;

    return 0;
}

Measured memory_bytes: 256
import re

S = str(input())
answer = 'WA'

if S[0] == 'A':
	if S.count('C') == 1:
		if 1< S.find('C') < len(S)-1:
			if len(re.findall('[A-Z]',S)) ==2:
				answer = 'AC'
				
print(answer)


Measured memory_bytes: 3188
#include<iostream>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<string>
#include<algorithm>
#include<queue>
using namespace std;
string s;
long long realsum;
void dfs(long long step,long long sum,long long nowsum){
  if(step==s.size()-1){
    realsum+=(long long)sum+nowsum*10+s[step]-'0';
    return;
  }
  dfs(step+1,(sum+nowsum*10+s[step]-'0'),0);
  dfs(step+1,sum,nowsum*10+s[step]-'0');
}
int main(){
  cin>>s;
  dfs((long long)0,(long long)0,(long long)0);
  cout<<realsum<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 100009 /// Still trying to be normal
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    ll ans=0;
    rep(i,1,n+1){
        rep(j,1,n+1){
            rep(k,1,n+1){
                ans+=__gcd(i,__gcd(j,k));
            }
        }
    }
    cout<<ans<<'\n';
    return 0;   
}   

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

struct Union_find
{
    vector<int> par;
    vector<int> rank;

    Union_find(int n) : par(n), rank(n)
    {
        for (int i = 0; i < n; i++)
        {
            par[i] = i;
            rank[i] = 0;
        }
    }

    int root(int x)
    {
        return par[x] == x ? x : par[x] = root(par[x]);
    }

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

    void unite(int x, int y)
    {
        x = root(x);
        y = root(y);
        //根にのみランクが保持されればいい
        if (rank[x] < rank[y])
            par[x] = y;
        else
        {
            par[y] = x;
            if (rank[x] == rank[y])
                rank[x]++;
        }
        return;
    }
};

int main(){
    int n,t;
    cin >> n >> t;
    vector<int> v(n);
    rep(i, n) cin >> v[i];

    ll sum = 0;
    for (int i = 1; i < n; i++){
        if (v[i]-v[i-1] > t){
            sum += t;
        }
        else
            sum += v[i] - v[i - 1];
    }
    sum += t;
    cout << sum << endl;
}

Measured memory_bytes: 1024
from collections import deque

N,M = map(int, input().split())

graph = [[] for i in range(N)]
for i in range(M):
    L,R,D = map(int, input().split())
    graph[L-1].append([R-1, D])
    graph[R-1].append([L-1, -D])

dist = [int(1e10)] * N

def bfs(id):
    Q = deque()
    Q.append(id)
    dist[id] = 0

    while len(Q) != 0:
        v = Q.popleft()

        for edge in graph[v]:
            u, d = edge[0], edge[1]

            if dist[u] == int(1e10):
                dist[u] = dist[v] + d
                Q.append(u)
            elif dist[u] != dist[v] + d:
                print("No")
                exit()


for i in range(N):
    if dist[i] == int(1e10):
        bfs(i)

print("Yes")




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

using namespace std;

#ifdef WIN32
	#define I64 "%I64d"
#else
	#define I64 "%lld"
#endif

typedef long long ll;

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(s) s.begin(), s.end()
#define sz(s) (int(s.size()))
#define fname "a"
#define MAXN 55

int n, p;
int a[MAXN];
ll d[MAXN][2];

int main()
{
	#ifdef LOCAL
	freopen(fname".in", "r", stdin);
	freopen(fname".out", "w", stdout);
	#endif

	scanf("%d%d", &n, &p);
	for (int i = 0; i < n; ++i)
		scanf("%d", &a[i]);

	d[0][0] = 1;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < 2; ++j) {
			d[i + 1][j] += d[i][j];
		}
		for (int j = 0; j < 2; ++j) {
			d[i + 1][(j + a[i]) % 2] += d[i][j];
	   }
	}
	cout << d[n][p] << endl;

	return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn max<T: std::cmp::PartialOrd>(a: T, b: T) -> T {
    if a > b {
        return a;
    } else {
        return b;
    }
}

fn main() {
    let s: String = read();
    let t: String = read();

    let si: Vec<char> = s.chars().collect();
    let ti: Vec<char> = t.chars().collect();

    let mut dp = vec![vec![0; t.len()+1]; s.len()+1];

    for i in 0..si.len() {
        for j in 0..ti.len() {
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1]);
            if si[i] == ti[j] {
                dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1);
            }
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j]);
        }
    }

    let mut i = s.len();
    let mut j = t.len();
    let mut ans = "".to_string();

    while i > 0 && j > 0 {
        if dp[i][j] == dp[i-1][j] {
            i -= 1;
        } else if dp[i][j] == dp[i][j-1] {
            j -= 1;
        } else {
            ans.push(si[i-1]);
            i -= 1;
            j -= 1;
        }
    }

    ans = ans.chars().rev().collect();
    println!("{}", ans);
}


Measured memory_bytes: 41212
#include <iostream>
using namespace std;
int main(){
  int n,i,t,sum,data[7];
  string in;
  while(1){
    cin >> n;
    if(n==0) break;
    sum=0;
    for(i=0;i<=6;i++) data[i]=i;
    for(i=0;i<n;i++){
      cin >> in;
      if(in=="North"){
	t=data[1];
	data[1]=data[2];
	data[2]=data[6];
	data[6]=data[5];
	data[5]=t;
      }
      else if(in=="East"){
	t=data[1];
	data[1]=data[4];
	data[4]=data[6];
	data[6]=data[3];
	data[3]=t;
      }
      else if(in=="West"){
	t=data[1];
	data[1]=data[3];
	data[3]=data[6];
	data[6]=data[4];
	data[4]=t;
      }
      else if(in=="South"){
	t=data[1];
	data[1]=data[5];
	data[5]=data[6];
	data[6]=data[2];
	data[2]=t;
      }
      else if(in=="Right"){
	t=data[2];
	data[2]=data[3];
	data[3]=data[5];
	data[5]=data[4];
	data[4]=t;
      }
      else{
	t=data[2];
	data[2]=data[4];
	data[4]=data[5];
	data[5]=data[3];
	data[3]=t;
      }
      sum+=data[1];
    }
    cout << sum+1 << endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename T>
void print_vec(const vector<T>& v, int num=0){
  if(num == 0) num = (int)v.size();
  for(int i=0; i<num; i++){ cout << v[i]; if(i!=num-1) cout << " ";}
  cout << endl;
}

template <typename T>
void print_pairvec(const vector<T> &v, int num=0){
  if(num == 0) num = (int)v.size();
  for(int i=0; i<num; i++){ cout << v[i].first << v[i].second; if(i!=num-1) cout << " ";}
  cout << endl;
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

int main(){
  int n, qt;
  cin >> n >> qt;
  using P = pair<string, int>;
  queue<P> qu;
  for(int i=0; i<n; i++){
    string name;
    int time;
    cin >> name >> time;
    qu.push(P(name, time));
  }

  int t = 0;
  while(!qu.empty()){
    string name = qu.front().first;
    int time = qu.front().second;
    qu.pop();
    if(time <= qt){
      t += time;
      cout << name << " " << t << endl;
    } 
    else{
      t += qt;
      time -= qt;
      qu.push(P(name, time));
    }
  }
  
  return 0;
}




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

using namespace std;

int main(void){

    int N,K,x[N+1],ans=0;

    cin >> N >> K;

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

    for(int i = 0; i < N; i++){
        ans += min(x[i],K - x[i]);
    }

    cout << ans * 2 << "\n";

return 0;
}


Measured memory_bytes: 256
N, Q = map(int, input().split())
S = input()

c = [0]
for j in range(1, N):
    if S[j - 1] == 'A' and S[j] == 'C':
        c.append(c[-1] + 1)
    else:
        c.append(c[-1])

# 0 1 1 1 2 2 3
# A C A A C A C
# 1 2 3 4 5 6 7
for i in range(Q):
    l, r = map(int, input().split())
    print(c[r - 1] - c[l - 1])


Measured memory_bytes: 6100
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

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

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

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


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------

int main(){
ll n;
cin>>n;
ll ans=1;
for(int i=1;i<=n;i++){
    ans=(ans*i)%mod;
}
cout<<ans%mod<<endl;
}










Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)
h = Hash.new(0)
a.each {|e| h[e] += 1}

sum = 0
h.each_value {|v| sum += v * (v - 1) / 2}

a.each {|e| puts h[e] == 0 ? sum : sum - h[e] + 1}

Measured memory_bytes: 28676
#include <stdio.h>

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

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main() 
{
	string s;
	cin>>s;
	map<string,int> day;
	day["SUN"]=7;
	day["MON"]=6;
	day["TUE"]=5;
	day["WED"]=4;
	day["THU"]=3;
	day["FRI"]=2;
	day["SAT"]=1;
	cout<<day[s]<<endl;
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int input(){
	int N;
	scanf("%d", &N);
	return N;
}

int run(int N){
	int i, ta, tb, sa = 0, sb = 0;
	for( i = 0; i < N; i++ ){
		scanf("%d %d", &ta, &tb);
		if( ta > tb ){
			sa += ta + tb;
		}else if( ta < tb ){
			sb += ta + tb;
		}else{
			sa += ta;
			sb += tb;
		}
	}
	printf("%d %d\n", sa, sb);
	return 0;
}

int main(){
	int N;
	while( N = input() ){ run(N); }
	return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<cctype>
using namespace std;



int main(void)
{
  int n,cn;
  cin>>n;
  cn=n;
  int wa=0;
  while(cn){
    wa+=cn%10;
    cn/=10;
  }
  if(n%wa){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
  return 0;
}



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

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

    cout<<0<<endl;
    cin>>s;
    if(s=="Vacant"){
        return 0;
    }
    int low=0,high=n;
    string t="";
    while(t!="Vacant"){
        int mid=(high+low)/2;
        cout<<mid<<endl;
        cin>>t;
        if((mid&1)^(s==t)) low=mid;
        else high=mid;
    }

    return 0;
}

Measured memory_bytes: 3852
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
    string s;
    int k;
    cin>>s>>k;
    vector<string> vec;
    for(int i=0;i<s.size();i++){
        for(int j=1;j<=k;j++){
        string tmp=s.substr(i,j);
        vec.push_back(tmp);
        }
    }
    sort(vec.begin(),vec.end());
     vec.erase(unique(vec.begin(),vec.end()),vec.end());
     cout<<vec.at(k-1)<<endl;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  
  string s;
  cin>>s;
  
  bool ans= false;
  
  if(s[0]==s[1]&&s[2]==s[3]&&s[0] !=s[2]) ans=true;
  if(s[0]==s[2]&&s[1]==s[3]&&s[0] !=s[1]) ans=true;
  if(s[0]==s[3]&&s[1]==s[2]&&s[0] !=s[1]) ans=true;
  
  if(ans){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
  
    
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

#define N 10000

int IsPrime(int num);

int main(void){

	int n,count,check;
	int A[N];

	
	count = 0;
	
	scanf("%d",&n);

	for(int i=0;i<n;i++){

		scanf("%d",&A[i]);

		}
	
	for(int i=0;i<=n;i++){
		
		check = IsPrime(A[i]);
		
		if(check==1){count++;}
		
	}
	
	
	
	printf("%d\n",count);


	return 0;
}


int IsPrime(int num)
{
	int c=0;
	
	if (num < 2){return c;}
	else if (num == 2){return c+1;}
	else if (num % 2 == 0){return c;}

    double sqrtNum = sqrt(num);
	
	
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            
            return c;
        }
    }

    
    return c+1;
}


Measured memory_bytes: 2744
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
	cin >> N;
	VI B(N);
	REP(i, N-1)cin >> B[i];
	int ans = 0;
	FOR(i,1, N - 1) {
		ans += min(B[i], B[i - 1]);
	}
	ans += B[0];
	ans += B[N - 2];
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <list>
using namespace std;
void  display_list(list<int> output){
	list<int>::iterator it;
	for  (it  =  output.begin();  it  !=  output.end();  it++){
		printf("%d ",  *it);
	}
	printf("\n");
}
int main() {
	int n,temp;
	int counter=1;
	list<int> output;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>temp;
		if(counter%2==0){
			output.push_front(temp);	
		}
		else{
			output.push_back(temp);
		}
		counter++;
	}
	if(n%2!=0){
		output.reverse();
	}
	display_list(output);
	return 0;
}

Measured memory_bytes: 14720
#include <bits/stdc++.h>
using namespace std;
int N, maxi = -1;
map<string, int> vote;
int main()
{
    cin>>N;
    for(int i = 0; i<N; ++i)
    {
        string str;
        cin>>str;
        vote[str]++;
        maxi = max(maxi, vote[str]);
    }
    for(auto i:vote)
    {
        if(i.second==maxi)
            cout<<i.first<<"\n";
    }
}

Measured memory_bytes: 25216
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Mod (int)1000000007
#define INFTY (int)INT_MAX
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(S, s) S.find(s) != string::npos

int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    Rep(i, K) {
        if (B <= A) B *= 2;
        else if (C <= B) C *= 2;
    }
    if (B > A && C > B) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3600
//#define DEB1 //input from input.txt
//#define NDEBUG
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <thread>
#include <mutex>
#include <iomanip>
#include <cassert>

#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))
#define ALL(t) (t).begin(),(t).end()
#define FILL(a,c) fill(a, a+ sizeof(a)/sizeof(*a),c)
#define FILL2D(A,c) fill(A[0], A[0] +sizeof(A)/sizeof(**A),c)
#define FILL3D(A,c) fill(A[0][0], A[0][0] +sizeof(A)/sizeof(***A),c)
#define REP(i,m) for(int i=0;i<(m);++i)
// closed interval, inverse repeat
#define CIREP(i,start,fin) for(int i=(start);i>=(fin);i--)
#define CREP(i,start,fin) for(int i=(start);i<=(fin);i++)
#define RNG(i,start,fin) for(int i=(start);i<(fin);i++)
#define IN(a, x, b) (a<=x && x<b)
#define PB push_back
#define SZ(x) (int)(x).size()

using namespace std;

using LL = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<LL,LL>;
using VI = vector<int>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VVI = vector<VI>;
const LL LINF = 1001002003004005006ll;
/* 
template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,SZ(v))i>>v[j];return i;}

template<typename T>string join(const vector<T>&v)
{stringstream s;REP(i,SZ(v))s<<' '<<v[i];return s.str().substr(1);}

template<typename T>inline ostream& operator<<(ostream&o,const vector<T>&v)
{if(SZ(v))o<<join(v);return o;}
*/

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}




/*
constant values
*/

//const int dx[] = {1,0,-1,0};
//const int dy[] = {0,1,0,-1};
//const int MX = 31001;

//const ll INF= 1LL<<60 ;//INF = 1001001001001; //1e9


// Main program
void solve(){
    LL N,a,b;
    cin >> N >> a >> b;
    if((b-a)%2==0){
        cout << (b-a)/2;
        return;
    }
    LL left;
    LL right;
    left = ((b - a)-1)/2+a;
    right = (N-(a+N-b+1))/2+(N-b+1);
    cout << min(left,right) << endl;
    return;
}



// ----------------------------------------------
int main(){

#ifdef DEB1
    cout << "DEBUG MODE"  << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf()); //for debug
#endif

    int T=1; 

    for (int i = 0; i < T; ++i) {
        solve();
    }

    return 0;
}

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

int main() {
  int a,b;
  cin >>a>>b;
  cout << a*b<<endl;
  return 0;
}

Measured memory_bytes: 3624
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() { return readln.chomp.to!int; }
int[] readints() { return readln.split.map!(to!int).array; }

void calc(Vec2 p, Vec2 a, Vec2 b) {
    auto ab = b - a;
    auto ap = p - a;

    auto e = ab.normalized;
    // ベクトル ap のベクトル ab への正射影ベクトルを求める
    auto ah = ap.dot(e) * e;

    auto px = (ah - ap) * 2;
    auto x = p + px;
    writefln("%.8f %.8f", x.x, x.y);
}

void main() {
    auto xs = readints();
    auto p1 = Vec2(xs[0], xs[1]);
    auto p2 = Vec2(xs[2], xs[3]);

    int q = readint();
    for (int i = 0; i < q; i++) {
        auto xy = readints();
        auto p = Vec2(xy[0], xy[1]);
        calc(p, p1, p2);
    }
}

struct Vec2 {
    immutable double x;
    immutable double y;

    this(double x, double y) {
        this.x = x;
        this.y = y;
    }

    Vec2 opNeg() { return Vec2(-this.x, -this.y); }
    Vec2 opAdd(Vec2 other) { return Vec2(this.x + other.x, this.y + other.y); }
    Vec2 opSub(Vec2 other) { return Vec2(this.x - other.x, this.y - other.y); }
    Vec2 opMul(double d) { return Vec2(this.x * d, this.y * d); }

    double dot(Vec2 other) { return this.x * other.x + this.y * other.y; }
    double cross(Vec2 other) { return this.x * other.y - other.x * this.y; }
    double mag() { return sqrt(magSq()); }
    double magSq() { return this.x * this.x + this.y * this.y; }

    Vec2 normalized() {
        auto m = mag();
        if (m != 0 && m != 1)
            return Vec2(this.x / m, this.y / m);
        return this;
    }

    static double distance(Vec2 a, Vec2 b) {
        return (a - b).mag();
    }
}



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

using namespace std;

int main() {
	int a, ans=0,con=0;
	cin >> a;
	for (int i = 1; i > 0; i++,con++) {
		if (ans == a)break;
		if (ans + i > a) {
				con++;
				break;
			
		}
		else ans +=i;
	}
	cout << con <<endl;
	return 0;
}

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

#define S_STRING_MAX (200000+1)

int StringTransformation(char* s, char* t) {
    int length = strlen(s);

    for(int i = 0; i < length; i++){
        if(t[i] != s[i]){
            char c1 = s[i];
            char c2 = t[i];
            for(int j = 0; j < length; j++){
                if(s[j] == c1){
                    if(j < i){
                        return 0;
                    }
                    s[j] = c2;
                }
                else if(s[j] == c2){
                    if(j < i){
                        return 0;
                    }
                    s[j] = c1;
                }
            }
        }
    }

    return strcmp(s, t) == 0;
}

int main(void){
    char s[S_STRING_MAX], t[S_STRING_MAX];
    scanf("%s\n%s", s, t);

    if(StringTransformation(s, t) != 0){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}


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

template<typename T>
istream& operator >> (istream& istr, vector<T>& v){
    for(T& x: v) istr >> x;
    return istr;
}

template<typename T, typename U>
istream& operator >> (istream& istr, pair<T,U>& p){
    istr >> p.first >> p.second;
    return istr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<T>& v){
    if(!v.empty()){
        ostr << v.front();
        for(auto itr = ++v.begin(); itr != v.end(); itr++)
            // ostr << *itr;
            ostr << " " << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, pair<T,U>& p){
    // ostr << p.first << p.second;
    ostr << p.first << ", " << p.second;
    return ostr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<vector<T>>& vv){
    if(!vv.empty()){
        ostr << vv.front();
        for(auto itr = ++vv.begin(); itr != vv.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, vector<pair<T,U>>& vp){
    if(!vp.empty()){
        ostr << vp.front();
        for(auto itr = ++vp.begin(); itr != vp.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

typedef long long ll;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<double> vd;
// vll x(n); x[i]=a;
typedef vector<vll> vvll;
typedef vector<vc> vvc;
typedef vector<vd> vvd;
// vvll x(m,vi(n)); x[i][j]=a;
typedef pair<ll,ll> pll;
typedef pair<double,double> pd;
typedef vector<pll> vpll;
typedef vector<pd> vpd;
// vpll x(n); x[i]={a,b}; x[i].first/second;

#define PI 3.1415926535897932
#define EPS 1e-12
#define INF (ll)1e+12
#define REP(i,n) for(ll i=0; i<(n); i++)
#define RREP(i,n) for(ll i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORR(i,a,b) for(ll i=(b)-1; i>=(a); i--)
#define fix(x) cout << fixed << setprecision(x)
#define dump(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()

template<typename T> T sum(vector<T>& v){return accumulate(all(v), (T)0);}
template<typename T> inline void sort(vector<T>& v){sort(all(v));}
template<typename T> inline void rsort(vector<T>& v){sort(all(v), greater<T>());}
template<typename T> inline void chmin(T& a, T b){if(a>b) a=b;}
template<typename T> inline void chmax(T& a, T b){if(a<b) a=b;}

int main(){
    vll a(3);
    cin >> a;
    swap(a[0],a[1]);
    swap(a[0],a[2]);
    cout << a << endl;
    return 0;
}


Measured memory_bytes: 256
import math
N, K = map(int, input().split())
A = input().split()
t = A.index("1")
if (N - 1) % (K - 1) == 0 and t % (K - 1) == 0 and t != 0 and t != N - 1 and K != 2:
  print(math.ceil((N - 1)/(K - 1)) + 1)
else:
  print(math.ceil((N - 1)/(K - 1)))


Measured memory_bytes: 10420
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
import java.util.*
import kotlin.math.*

fun main() {
    var fs = Atcoder.FastReader()
    var n = fs.nextInt()
    var a = fs.readIntArray(n)
    var ans = 0
    for (i in 0 until a.size-2) {
        for (j in i+1 until a.size-1) {
            for (k in j+1 until a.size) {
                if(a[i] != a[j] && a[i] != a[k] && a[j] != a[k]) {
                    var max = max(max(a[i], a[j]), a[k])
                    var min = min(min(a[i], a[j]), a[k])
                    var sum = a[i] + a[j] + a[k]
                    if (sum - max - min < max && sum - max > max) ans++
                }
            }
        }
    }
    println(ans)
}

class Atcoder {
    internal class FastReader {
        private var br: BufferedReader = BufferedReader(InputStreamReader(System.`in`))
        private var st: StringTokenizer? = null

        operator fun next(): String {
            while (st == null || !st!!.hasMoreElements()) {
                try {
                    st = StringTokenizer(br.readLine())
                } catch (e: IOException) {
                    e.printStackTrace()
                }

            }
            return st!!.nextToken()
        }

        fun nextInt(): Int {
            return Integer.parseInt(next())
        }

        fun nextLong(): Long {
            return java.lang.Long.parseLong(next())
        }

        fun nextDouble(): Double {
            return java.lang.Double.parseDouble(next())
        }

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

        fun readIntArray(n: Int): IntArray {
            val a = IntArray(n)
            for (i in 0 until n) a[i] = nextInt()
            return a
        }

        fun readLongArray(n: Int): LongArray {
            val a = LongArray(n)
            for (i in 0 until n) a[i] = nextLong()
            return a
        }

        fun readDoubleArray(n: Int): DoubleArray {
            val a = DoubleArray(n)
            for (i in 0 until n) a[i] = nextDouble()
            return a
        }
    }
}


Measured memory_bytes: 35208
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
#define INF 100000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 100005;
const int MOD = 1000000007;
int main(){
    int n,m;
    cin>>n>>m;
    vector<int>s[m];
    REP(i,m){
        int k;
        cin>>k;
        REP(j,k){
            int a;
            cin>>a;
            a--;
            s[i].push_back(a);
        }
    }
    vector<int>p(m);
    REP(i,m){
        cin>>p[i];
    }
    int ans=0;
    for(int bit=0;bit<(1<<n);bit++){
        vector<int> S;
        REP(i,n){
            if(bit & (1<<i)){
                S.push_back(i);
            }
        }
        bool f=true;
        REP(i,m){
            int cnt=0;
            REP(j,SZ(S)){
                REP(k,SZ(s[i])){
                    if(S[j]==s[i][k]){
                        cnt++;
                        break;
                    }
                }
            }
            if(cnt%2!=p[i]){
                f=false;
                break;
            }
        }
        if(f)ans++;
    }
    OUT(ans);
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)

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

    long long ans = 1;
    for (long long i = 1; i <= n; i++) {
        ans *= i;
        ans %= (1000000007);
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn dfs(e: &Vec<Vec<usize>>, cur: usize, par: usize, d: usize, c: usize, dp: &mut Vec<Vec<bool>>, color: &mut Vec<usize>) {
    if dp[cur][d] {
        return;
    }
    for i in 0..d+1 {
        dp[cur][i] = true;
    }
    if color[cur] == 0 {
        color[cur] = c
    }
    if d == 0 {
        return;
    }
    for &nd in e[cur].iter() {
        if nd != par {
            dfs(e, nd, cur, d-1, c, dp, color);
        }
    }
}

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
      m: usize,
      abs: [(usize1,usize1); m],
      q: usize,
      mut vdcs: [(usize1, usize, usize); q],
    }

    let mut e = vec![vec![]; n];
    for (a, b) in abs {
        e[a].push(b);
        e[b].push(a);
    }

    let mut dp = vec![vec![false; 11]; n];
    let mut color = vec![0; n];
    vdcs.reverse();
    for (v, d, c) in vdcs {
        dfs(&e, v, n, d, c, &mut dp, &mut color);
    }

    for i in 0..n {
        puts!("{}\n", color[i]);
    }
}


Measured memory_bytes: 22780
#include<stdio.h>
int main()
{
	int Q,c,a,n,m,i;
	scanf("%d",&Q);
	
	for(i = 0; i < Q; i++){
			scanf("%d %d %d",&c,&a,&n);
		m = 0;
		while(1){
			if(c >= 1 && a>= 1 && n >= 1){
				m++;
				c--;
				a--;
				n--;
			}
			else if(c >= 2 && a >= 1){
				m++;
				c = c-2;
				a--;
			}
			else if(c >=3){
				m++;
				c = c-3;
			}
			else
				break;
		}
		printf("%d\n",m);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007;



int main() {
    ll L,R;
    cin>>L>>R;
    vector<ll> amari(0);
    rep(i,R-L+1){
        if(i>=4040)break;
        amari.pb((L+i)%2019);
    }
    int x=sz(amari);
    int ans=5000;
    rep(i,x){
        for(int j=i+1;j<x;j++){
            int now=amari.at(i)*amari.at(j)%2019;
            chmin(ans,now);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3612
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


import numpy as np
from numba import njit

N, W_max = ints()
W, V = read_col(N)
W = np.array(W, dtype=np.int64)
V = np.array(V, dtype=np.int64)

'''
dp[i,j] ... 重さの最小 (:iまで考慮したとき、価値がちょうどjのとき)
答えはW以下の数字が入ってるマスの一番左側

更新則
chmin(dp[i+1,j+V[i]] , dp[i, j]+W[i]) #ナップサックに入れた場合
chmin(dp[i+1,j] , dp[i, j]) # ナップサックに入れなかった場合
'''


@njit('(i8, i8, i8[:], i8[:])', cache=True)
def solve(N, W_max, W, V):
    V_max = np.sum(V) + 1
    dp = np.full((N + 1, V_max), 10**12, dtype=np.int64)
    # 初期化
    dp[0,0] = 0  # 一個も選ばず価値が0なら必ず重さも0

    # 更新
    for i in range(N):
        dp[i + 1, :] = np.minimum(dp[i + 1, :], dp[i, :])
        for j in range(V_max):
            jv = j + V[i]
            if jv>=V_max:
              break
            dp[i + 1, jv] = min(dp[i + 1, jv], dp[i, j] + W[i])

    # 左から見てく
    for j in range(V_max - 1, -1, -1):
        if np.any(dp[:, j] <= W_max):
            print(j)
            return


solve(N, W_max, W, V)


Measured memory_bytes: 197584
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    string StrOrigin;
    cin >> StrOrigin;

    int StrLength = StrOrigin.length();

    string StrReplace;

    for (int i = 0; i < StrLength; i++) {
        StrReplace = StrReplace + "x";
    }
    cout << StrReplace;

    return 0;
}

Measured memory_bytes: 256
// 6/18 振り返り
#include <iostream>
#include <vector>
#include <string>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); ++i)

ll INF = 1e18;
ll dp[200005][4];

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    int k = 1 + n % 2;  // 何個余分な×を入れられるか？偶数なら１個、奇数なら２個。
    rep(i, n+1) rep(j, k+1) dp[i][j] = -INF;
    dp[0][0] = 0;
    rep(i, n) {
        rep(j, k+1) {
            // ×（余白）を一個挿入する場合
            // dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]);
            dp[i+1][j+1] = dp[i][j];

            // x（余白）を挿入しない場合
            ll now = dp[i][j];
            if ((i+j)%2 == 0) now += a[i];
            dp[i+1][j] = max(dp[i+1][j], now);
        }
    }
    ll ans = dp[n][k];
    cout << ans << endl;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	int N; cin >> N;
	cout << 180 * (N - 2) << endl;
}


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

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<string> words;
    char front,back;
    bool f = true;
    for(int i=0;i<N;i++){
        string word;
        cin >> word;
        if(i==0){
            back = word[word.size()-1];
        } else{
            vector<string>::iterator itr = find(words.begin(),words.end(),word);
            if(back==word[0] && itr == words.end()){
                front = word[0];
                back = word[word.size()-1];
            } else{
                f = false;
                break;
            }
        }
        words.push_back(word);
    }

    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
def partition(a, p, r)
  x = a[r]
  i = p-1
  (p..r-1).each do |j|
    next unless a[j] <= x
    i = i+1
    tmp = a[i]
    a[i] = a[j]
    a[j] = tmp
  end
  tmp = a[i+1]
  a[i+1] = "[#{a[r]}]"
  a[r] = tmp
  return i+1
end
_, a = readlines.map(&:chomp).map {|l| l.split.map(&:to_i)}
partition(a, 0, a.size - 1)
puts a.join(' ')


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

using namespace std;

#define int long long
#define ld long double
#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()
#define x first
#define y second

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 3e5 + 10;

map<int, map<int, int>> mp;
int a[maxn], b[maxn];
vector<int> c[maxn];

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int h, w, n;
    cin >> h >> w >> n;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        a[x]++;
        b[y]++;
        mp[x][y] = 1;
        c[x].push_back(y);
    }
    multiset<int> s;
    for (int i = 1; i <= w; i++) {
        s.insert(b[i]);
    }
    int ans = 0;
    for (int i = 1; i <= h; i++) {
        for (auto &el : c[i]) {
            auto it = s.find(b[el]);
            ans = max(ans, a[i] + b[el] - 1);
            if (s.end() != it) {
                s.erase(it);
            }
        }
        if (sz(s)) {
            auto it = *s.rbegin();
            ans = max(ans, a[i] + it);
        }
        for (auto &el : c[i]) {
            s.insert(b[el]);
        }
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 85692
#include<iostream>
#include<algorithm>
using namespace std;
long l,r,lim=1<<20;
bool isp[1<<20],isplr[1<<20];
int now[1<<20],cnt[1<<20];
main()
{
	cin>>l>>r;
	isp[0]=isp[1]=1;
	for(int i=l;i<=r;i++)now[i-l]=i;
	for(long i=2;i<lim;i++)
	{
		if(isp[i])continue;
		for(long j=i*2;j<lim;j+=i)isp[j]=1;
		for(long j=(l+i-1)/i*i;j<=r;j+=i)
		{
			while(now[j-l]%i<1)now[j-l]/=i,cnt[j-l]++;
		}
	}
	int ans=0;
	for(int i=l;i<=r;i++)if(!isp[cnt[i-l]+(now[i-l]>1)])ans++;
	cout<<ans<<endl;
}


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

/* 参考:　貰う DP と配る DP、メモ化再帰、個数制限なしナップサック問題 @drken https://qiita.com/drken/items/ace3142967c4f01d42e9#%E8%A7%A3%E6%B3%95-1-1-%E3%83%88%E3%83%83%E3%83%97%E3%83%80%E3%82%A6%E3%83%B3%E3%81%AB-n-%E3%82%92%E9%99%8D%E4%B8%8B%E3%81%97%E3%81%A6%E3%81%84%E3%81%8F%E3%83%A1%E3%83%A2%E5%8C%96%E5%86%8D%E5%B8%B0 */

public class Main {
	static final int MAX_N = 110000;
	static int[] dp = new int[MAX_N];
	static {
		Arrays.fill(dp, MAX_N); // 初期化 Infinity
		dp[0] = 0;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		calc(N);
		System.out.println(dp[N]);
	}

	static void calc(int N) {
		for (int n = 1; n <= N; n++) {
			for (int pow6 = 1; pow6 <= n; pow6*=6) {
				dp[n] = Math.min(dp[n], dp[n-pow6] + 1);
			}
			for (int pow9 = 1; pow9 <= n; pow9*=9) {
				dp[n] = Math.min(dp[n], dp[n-pow9] + 1);
			}
		}
	}
}


Measured memory_bytes: 20948
#include<iostream>
#include<stdio.h>
using namespace std;
int okane(int a,int b,int c,int d,int e,int f){
	return a+b*5+c*10+d*50+e*100+f*500;
	}
int main(){
	int a1,a5,a10,a50,a100,a500;
	cin>>a1>>a5>>a10>>a50>>a100>>a500;
	if(okane(a1,a5,a10,a50,a100,a500)>=1000){
		cout<<1<<endl;
		}
		else cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 1164