akhauriyash/Code-Regression huggingface dataset:
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const Q  = parseInt(arg[0]);
    const lr = arg.slice(1, Q + 1);
    
    let primeMap = [];
    
    // 100000までの素数表を作る
    for(let i=1; i<=100000; i++) {
        if(i === 1) {
            primeMap[i] = false;
            continue;
        }
        
        let flag = true;
        
        for(let j=2; j<i; j++) {
            if(i % j === 0) {
                flag = false;
                break;
            }
            
            if(j > Math.sqrt(i)) {
                break;
            }
        }
        
        if(flag) primeMap[i] = true;
    }
    
    let totalSum = [...Array(100000)].fill(0);
    
    // 奇数のうち2017-likeかどうかを判定する
    for(let i=1; i<=100000; i += 2) {
        // NもN+1も素数かどうか
        if(primeMap[i] && primeMap[((parseInt(i) + 1) / 2)]) {
            totalSum[i]++;
        }
    }

    // 累積和に上書きする
    for(let i=1; i<=100000; i ++) {
        totalSum[i] += totalSum[i - 1];
    }
    
    let answer = [];
    
    // 累積和からlrの範囲をとる
    for(let i in lr) {
        let l = parseInt(lr[i].split(" ")[0]);
        let r = parseInt(lr[i].split(" ")[1]);
        
        answer.push(totalSum[r] - totalSum[l - 1]);
    }
    
    console.log(answer.join("\n"));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 52756
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
    var input = input.split("\n");
	//文字列から10進数に変換するときはparseIntを使います
    var input2 = input[1].split(" ");
  	
  	var length = input2.length
    var cnt = 0
    var arr = []
  
  	var ans = input2.reduce(function(a,b,c){
     
    	if (Number(input2[c]) >= Number(input2[c + 1]) ){
          cnt ++
        return cnt
        }else{
          arr.push(cnt)
          cnt = 0
    	return 0
        }
    }   
      ,[])
    ans = Math.max.apply(null,arr)
  console.log(ans)
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 27960
///////////////////////////////////////////
//root@NULLCT$(☝ ՞ਊ ՞)☝  << "Be accept!!"//
///////////////////////////////////////////
//#define BOOST
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int66_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>   //setfill(char)
#include <ios>       //left,right
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
#ifdef BOOST
#include <boost/multiprecision/cpp_int.hpp> // cpp_int
namespace mp = boost::multiprecision;
#endif
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;
using namespace std;
int setup(void) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); return 0; }
int lenght(char* str) { int i = 0; while (str[i])i++; return i; }
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int iinput(void) { int a = 0; cin >> a; return a; }
int dinput(void) { double a = 0; cin >> a; return a; }
string sinput(void) { string a = ""; cin >> a; return a; }
int kuriup(double a) { int b = int(a); if (a != b) { return b + 1; } else { return b; } }
int kuridown(double a) { int b = int(a); return b; }
int run(void);
int main() { setup(); run(); return 0; }
/////////////////////////////////////////////////////////////////////////////////////////
int run(void) {

  int n;
  cin>>n;
  cout<<(n+1)/2<<endl;

  return 0;
}



Measured memory_bytes: 256
using System;
using System.Linq;

namespace AtCoderBeginnerContest148
{
    class C_Snack
    {
        static void Main(string[] args)
        {
            var n = Console.ReadLine().Split().Select(x => int.Parse(x)).ToList();
            long valA = n[0];
            long valB = n[1];
            long valX = valA * valB;

            if (valA < valB)
            {
                var temp = valA;
                valA = valB;
                valB = temp;
            }

            var r = valA % valB;
            while(r != 0)
            {
                valA = valB;
                valB = r;
                r = valA % valB;
            }

            Console.WriteLine(valX / valB);
        }
    }
}

Measured memory_bytes: 13268
<?php

fscanf(STDIN, '%d %d', $n, $k);

$p = explode(' ', rtrim(fgets(STDIN), PHP_EOL));


function kitaiti($d) {
//    $sum = 0;
//    for ($i = $d; $i > 0; $i --) {
//        $sum += $i;
//    }
    return (float)(($d+1)*$d/2) / $d;
}

$ppp = [];
foreach ($p as $pp) {
    $ppp[] = kitaiti($pp);
}

$ppppp = [0 => 0];
for ($i = 0; $i < $n; $i++) {
//    var_dump($ppppp[$i-1] ,$ppp[$i]);
    $ppppp[$i+1] = $ppppp[$i] + $ppp[$i];
}

//var_dump($ppp,$ppppp);

$cache = 0.0;

for ($i = 0; $i < $n-$k+1; $i++) {
    $hoge = $ppppp[$i+$k] - $ppppp[$i];

    if ($cache < $hoge) {
        $cache = $hoge;
    }
}


echo sprintf('%7f', $cache).PHP_EOL;





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

int main()
{
  int n, w;
  scanf("%d%d", &n, &w);
  vector<ll> wt(n);
  vector<ll> c(n);
  vector<ll> dp(w+1, 0);
  for(int i=0;i<n;++i)
  {
      cin >> wt[i] >> c[i];
  }
  
  
  for(int i=0;i<n;++i)
  {
      for(int j=w;j>=wt[i];j--)
      {
          dp[j] = max(dp[j], c[i] + dp[j-wt[i]]);
      }
  }
  cout << dp[w];
}

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

long long ryuka( int x )
{
	long long a = 2;
	long long b = 1;
	long long r;
	if( x == 0 ) {
		return a;
	}
	else if( x == 1 ) {
		return b;
	}
	for( int i = 2; i <= x; i++ ) {
		r = a + b;
		a = b;
		b = r;
	}

	return r;
}

int main()
{
	long long ans;
	int n;

	cin >> n;

	ans = ryuka( n );

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<functional>
using namespace std;
#define LL long long
#define MOD 100000
#define inf 1999999999


int main() {
	int x;
	cin >> x;
	if (x >= 1200)cout << "ARC" << endl;
	else cout << "ABC" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <utility>
#include <map>
#include <inttypes.h>

int LCS(std::string s, std::string t){
    int n, m, c[1001][1001] = {0};
    n = s.size();
    m = t.size();
    int maxlen = 0;
    for(int i = 1; i <= n; i++){
        c[i][0] = 0;
    }
    for(int i = 1; i <= m; i++){
        c[0][i] = 0;
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(s[i - 1] == t[j - 1]){
                c[i][j] = c[i - 1][j - 1] + 1;
            }
            else{
                c[i][j] = std::max(c[i - 1][j], c[i][j - 1]);
            }
            maxlen = std::max(maxlen, c[i][j]);
        }
    }
    return maxlen;
}
int main(){
    int N;

    std::cin >> N;
    std::string s1, s2;
    for(int i = 0; i<N; i++){
        std::cin >> s1 >> s2;
        std::cout << LCS(s1, s2) << std::endl;
    }
    return 0;
}


Measured memory_bytes: 7064
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		char[] key = scanner.nextLine().toCharArray();
		char[] aFilledKey = String.valueOf(key).replaceAll("\\?", "a").toCharArray();
		char[] part = scanner.nextLine().toCharArray();
		List<String> possibleKeys = new ArrayList<>();
		int kLen = key.length;
		int pLen = part.length;

		for (int kIndex = kLen - 1; kIndex >= pLen - 1; kIndex--) {
			char[] keyCopy = Arrays.copyOf(aFilledKey, kLen);
			boolean found = true;
			for (int probe = 0; probe < pLen; probe++) {
				if (key[kIndex - probe] != part[pLen - 1 - probe] && key[kIndex - probe] != '?') {
					found = false;
					break;
				}
			}
			if (found) {
				for (int substIndex = 0; substIndex < pLen; substIndex++) {
					keyCopy[kIndex - pLen + 1 + substIndex] = part[substIndex];
				}
				possibleKeys.add(String.valueOf(keyCopy));
			}
		}

		System.out.println(possibleKeys.parallelStream().sorted().findFirst().orElse("UNRESTORABLE"));
	}
}


Measured memory_bytes: 29140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
inline int rnd(int x){
	return rand()%x;
}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=4005,mod=1000000007;
int n,m,k,dp[N],ans;
inline void add(int &a,int b){
	a=a+b>=mod?a+b-mod:a+b;
}
signed main(){
	n=read(); m=read(); k=read(); swap(n,m);
	int jb=k-1;
	dp[0]=1; 
	for(int i=0;i<(n+m-1)/(k-1);i++){
		int meiju=min(n,i*(k-1)),mmm=min(n,(i+1)*(k-1));
		for(int j=1;j<=meiju;j++)add(dp[j],dp[j-1]);
		for(int j=meiju;j>=0;j--){
			if(j+k<=mmm)add(dp[j+k],mod-dp[j]);
			if(j+((n-j)%jb==0?jb:(n-j)%jb)<=n&&(i+1)*jb-(j+((n-j)%jb==0?jb:(n-j)%jb))<m)ans=(ans+dp[j])%mod;
			//cout<<dp[j]<<" "<<i<<" "<<j<<" "<<(i+1)*jb-(j+(n-j)%jb)<<endl;
		}
	}
	cout<<(ans+mod)%mod<<endl;
}

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

const int MAX = 1000001; 

int factor[MAX] = { 0 }; 
 
void generatePrimeFactors() 
{ 
	factor[1] = 1; 

	for (int i = 2; i < MAX; i++) 
		factor[i] = i; 

	for (int i = 4; i < MAX; i += 2) 
		factor[i] = 2; 

	for (int i = 3; i * i < MAX; i++) { 
		if (factor[i] == i) { 
			for (int j = i * i; j < MAX; j += i) { 
				if (factor[j] == j) 
					factor[j] = i; 
			} 
		} 
	} 
} 

int calculateNoOFactors(int n) 
{ 
	if (n == 1) 
		return 1; 

	int ans = 1; 

	int dup = factor[n]; 

	int c = 1; 
	int j = n / factor[n]; 
	while (j != 1) { 
		if (factor[j] == dup) 
			c += 1; 
		else { 
			dup = factor[j]; 
			ans = ans * (c + 1); 
			c = 1; 
		} 
		j = j / factor[j]; 
	} 

	ans = ans * (c + 1); 

	return ans; 
} 

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

    long long ans=0;

    for(int i=1;i<n;i++)
    {
        ans+=calculateNoOFactors(i);
    }
	
    cout << ans << endl;
	return 0; 
} 


Measured memory_bytes: 7128
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
const int INF = numeric_limits<int>::max();
int weight[100005]; 
bool visited[100005];
vector<pi>graph[100005];
bool possible = true;

void dfs(int curr){
	visited[curr] = true;
	for(int i=0; i<graph[curr].size(); i++){
		int nxt = graph[curr][i].first;
		int dist = graph[curr][i].second;
		if(!visited[nxt]){
			weight[nxt] = weight[curr]+dist;
			dfs(nxt);
		}
		else{
			if(weight[nxt]!=weight[curr]+dist) possible = false;
		}
	} 
}

int main(){
	int n,m;
	cin>>n>>m;
	while(m--){
		int l,r,d;
		cin>>l>>r>>d;
		graph[l].push_back(pi(r,d));
		graph[r].push_back(pi(l,-1*d));
	}
	for(int i=1; i<=n; i++) if(!visited[i]) dfs(i);
	cout<<(possible?"Yes":"No");
}

Measured memory_bytes: 15344
/* ex 7_1
   B30095   */

#include <stdio.h>

/* a 2d point */
typedef struct{
    int x;
    int y;
}Point;

/* get next point of a sqaure in counterclockwise */
Point next_square_point(Point p1, Point p2){
    Point p3, vect;

    // vector from p1 to p2
    vect.x = p2.x - p1.x;
    vect.y = p2.y - p1.y;

    // rotate the vector 90 degrees and add it to p2
    p3.x = p2.x - vect.y ;
    p3.y = p2.y + vect.x;

    return p3;
}

int main(void){

    Point p1, p2, p3, p4;

    scanf("%d %d %d %d", &p1.x, &p1.y, &p2.x, &p2.y);
    
    p3 = next_square_point(p1, p2);
    p4 = next_square_point(p2, p3);

    printf("%d %d %d %d", p3.x, p3.y, p4.x, p4.y);

    return 0;
}

Measured memory_bytes: 1720
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
using ll = long long int;
const int MAX = 3001;
double p[MAX], dp[MAX][MAX];
int main() {
	int n,i,j;
	cin>>n;
	for(i=0;i<n;++i) {
		cin>>p[i];
	}
    
    dp[0][0] = 1-p[0];
    dp[0][1] = p[0];
	for(i=1;i<n;++i) {
		for(j=0;j<=i+1;++j) {
			if(j) dp[i][j] = dp[i-1][j]*(1-p[i]) + dp[i-1][j-1]*p[i];
			else dp[i][j] = dp[i-1][j]*(1-p[i]);
		}
	}

	double ans = 0;
	for(i=n/2+1;i<=n;++i) {
		ans += dp[n-1][i];
	}
	cout<<fixed<<setprecision(10)<<ans<<endl;
	return 0;
}

Measured memory_bytes: 68864
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,a;
    cin>>n;
    vector<pair<int,int>> v;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        v.push_back({a,i+1});
    }
    sort(v.begin(),v.end());
    for(auto x:v)
    {
        cout<<x.second<<" ";
    }
}


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

int main(){
   string a;
  cin >> a;
  int e;
  e =1000;
  for(int i=0;i<a.size()-2;i++){
    e = min(abs((a[i]-'0')*100+(a[i+1]-'0')*10+(a[i+2]-'0') -753),e);
  }
  cout << e << endl;
}
  
  
 


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<queue>
#include<string>
using namespace std;
using ll = long long;

struct Corr {
    ll y;
    ll x;
    ll depth;
};

ll N, M;  // 迷路の縦，横
ll s_y, s_x, g_y, g_x;  // スタート，ゴールの座標
ll y, x, depth;  // キューから取り出した座標
vector<string> vec;  // 座標を受け取る配列
vector<string> vv;
queue<Corr> q;

vector<ll> y_vec = {0, 0, -1, +1};  // 進む方向の簡便化，テクニックとして覚えておく．
vector<ll> x_vec = {-1, +1, 0, 0};  // ループで回すことで上下左右に移動できるようになっている

ll bfs() {
    ll ret = 0;
    while (!q.empty()) {
        Corr now = q.front(); q.pop();  // キューの先頭を取り出す
        y = now.y, x = now.x, depth = now.depth;  // 行，列が y, x になっているので注意
        // 上下左右 4 方向を探索．進むことができればキューに格納する．
        ret = max(ret,depth);
        for (ll i = 0; i < 4; ++i) {
            Corr next = {y + y_vec[i], x + x_vec[i], depth + 1};
            if (0 <= next.y && next.y <= N-1 && 0 <= next.x && next.x <= M-1 && vec[next.y][next.x] == '.') {
                vec[next.y][next.x] = 'x';  // 同じ場所を探索しないようにする
                q.push(next);
            }
        }
    }
    return ret;
}

int main(){
    ll ans = 0;
    cin >> N >> M;

    vv.resize(N);
    vec.resize(N);
    for (ll i = 0; i < N; ++i) cin >> vv[i];
    for(ll i=0;i<N;i++){
        for(ll j=0;j<M;j++){
            if(vv[i][j]=='.'){
                s_y=i, s_x=j; 
                for(ll k=0;k<N;k++) vec[k] = vv[k];
                vec[s_y][s_x]='x';
                Corr start = {s_y, s_x, 0};  // 初期位置の深さ(depth)は 0
                q.emplace(start);  // 初期位置をキューに格納
                ans = max(bfs(),ans);
            }
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;
public class Main {

	private static int max; // 要素の数
	private static int run; // 処理速度
	private static Object q[]; // queue
	private static String end[]; // 処理済み
	private static int count; // 処理済み数
	private static int front; // 先頭
	private static int rear; // 末尾
	private static int time; // 合計処理時間

	public static void main(String[] args) throws IOException{
		Scanner sc = new Scanner(System.in);

		max = sc.nextInt();
		run = sc.nextInt();

		q = new Object[max+1];
		front = rear = count = time = 0;
		end = new String[max];

		for(int i=0;i<max;i++) {
			String a = sc.next();
			int b = sc.nextInt();
			enqueue(a + " " +b);
		}

		while(true) {
			String[] line = dequeue().toString().split(" ");
			int x = Integer.parseInt(line[1]);
			// 処理時間以内なら
			if(x <= run) {
				time += x;
				end[count++] = line[0] + " " + Integer.toString(time);
			// 処理時間以上なら
			}else {
				line[1] = Integer.toString(x - run);
				enqueue(line[0] + " " + line[1]);
				time += run;
			}

			if(count == max) {
				break;
			}
		}

		show();

		sc.close();
	}

	public static void show() {
		for(int i=0;i<max;i++) {
			System.out.println(end[i]);
		}
	}

	/*
	 * ポインタの位置
	 */
	public static int next(int a) {
		return (a + 1) % max;
	}

	/*
	 * 入れる
	 */
	public static void enqueue(Object x) {
/*		if(next(rear) == front) {
			throw new IllegalStateException();
		}*/
		q[rear] = x;
		rear = next(rear);
	}

	/*
	 * 取り出す
	 */
	public static Object dequeue() {
		Object x = q[front];
		q[front] = null;
		front = next(front);
		return x;
	}
}


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

int index(vector<int> d, int x) {
    rep(i, d.size()) {
        if(d[i] >= x)
            return i;
    }
    return -1;
}

int main() {
    int n, ans = 0;
    cin >> n;
    vector<int> d(n);
    int halfn = n / 2;

    rep(i, n) cin >> d[i];

    ::sort(d.begin(), d.end());

    cout << d[halfn] - d[halfn-1] << endl;
}

Measured memory_bytes: 3784
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,k;
  cin>>a>>b>>k;
  for(int i=min(a,b);i>=1;i--){
    if(a%i==0&&b%i==0){
      k--;
      if(k==0){
        cout<<i<<endl;
        return 0;
      }
    }
  }
  assert(false);
}

Measured memory_bytes: 3668
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var strN = Console.ReadLine();
            var N = int.Parse(strN);

            var result = 0;
            foreach (var i in Enumerable.Range(1, strN.Length))
            {
                if (i <= 2) continue;
                var tmp = Shichigosan(i, new List<int>());
                result += tmp.Where(x => x <= N).Select(x => x.ToString())
                    .Where(x => x.Contains("3") && x.Contains("5") && x.Contains("7")).Count();
            }

            Console.WriteLine(result);
        }
        
        static List<int> Shichigosan(int digits, List<int> current)
        {
            if(digits == 0)
            {
                return current;
            }
            else if(current.Count == 0)
            {
                var newlist = new List<int>();
                newlist.Add(3);
                newlist.Add(5);
                newlist.Add(7);
                return Shichigosan(digits - 1, newlist);
            }
            else
            {
                var newlist = new List<int>();
                foreach(var x in current)
                {
                    newlist.Add(x * 10 + 3);
                    newlist.Add(x * 10 + 5);
                    newlist.Add(x * 10 + 7);
                }
                return Shichigosan(digits - 1, newlist);
            }
        }
    }
}


Measured memory_bytes: 11616
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)

int main()
{
    ll N, A, B, C, D, E;
    cin >> N >> A >> B >> C >> D >> E;
    ll sum_time = 0;
    sum_time = (N - 1) / min({A, B, C, D, E});
    sum_time += 5;
    cout << sum_time << endl;
}

Measured memory_bytes: 256
N = int(input())
F = [''.join(input().split()) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

x = [int(v, 2) for v in F]
rev = []
for i in range(1, 2 ** 10):
    cnt = [list(bin(i & v)[2:]).count('1') for v in x]
    rev.append(sum([P[j][cnt[j]] for j in range(N)]))
print(max(rev))

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

const int inf = 1e9;
const ll linf = 1e18;

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

    int n; cin >> n;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        static int m = inf;
        int p; cin >> p;
        if (p <= m) {
            ans++; m = p;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int B[33];
int C[33];

int main() {
	int N; cin >> N;
	for (int i = 0; i < N; i++) {
		int a;cin >> a;

		int cnt = 0;
		bool f = true;
		while (a) {
			if (a & 1) {
				if (f) {
					B[cnt]++;
					f = false;
				}
				C[cnt]++;
			}
			a >>= 1;
			cnt++;
		}
	}

	bool flag = true;
	int ans = 0;
	for (int i = 32; i >= 0; i--) {
		if (C[i] % 2) {
			if (B[i]) {
				for (int j = i - 1; j >= 0; j--)C[j]++;
				ans++;
			}
			else flag = false;
		}
	}

	cout << (flag ? ans : -1) << endl;
	

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define N 500000
#define nmax 50000
#define INFTY 100000

int n;
int num[N];

int main(){
    cin>>n;
    for (int i=0; i<n; i++){
        int a;
        cin>>a;
        num[i]=a;
    }
    int count=1;
    int memo=num[0];
    for (int i=1; i<n; i++){
        if (memo>num[i]){
            count+=1;
            memo=num[i];
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll mod = 1e9+7;


void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

// 線分 ab の偏角 返り値は[-π, π]
template<typename T>
T argument(const pair<T, T> &a, const pair<T, T> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

/* 注意 

    1LL<<60 * N とかのオーバーフローに気を付けろ
    制約がヒントになる、ちゃんと全ての制約を見ろ

*/

long double dist(long double const & x, long double const & y) {
    return sqrt(x*x + y*y);
}

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

    int N; std::cin >> N;
    std::vector<pair<long double, long double>> engines; 
    rep(i, N) {
        long double a, b; std::cin >> a >> b;
        if(a!=0 || b!=0) engines.push_back(make_pair(a, b));
    }
    pair<long double, long double> o(0, 0);
    std::sort(engines.begin(), engines.end(), [&](auto l, auto r){ return argument(o, l)<argument(o, r); });

    long double ans = 0.0;
    int m = engines.size();
    rep(i, m) {
        long double x = 0.0, y = 0.0;
        rep(j, m) {
            x += engines[(i+j)%m].first;
            y += engines[(i+j)%m].second;
            chmax(ans, dist(x, y));
        }
    }
    std::cout << std::setprecision(15) << ans << std::endl;
    
    return 0;
}

Measured memory_bytes: 384
N = int(input())
A = map(int, input().split())

ni = 0
yon = 0
hoka = 0

for a in A:
    if a % 4 == 0:
        yon += 1
    elif a % 2 == 0:
        ni += 1
    else:
        hoka += 1

if ni > 0:
    if yon >= hoka:
        print("Yes")
    else:
        print("No")
else:
    if yon >= hoka-1:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 17032
// #define _GLIBCXX_DEBUG
// #pragma GCC optimize("Ofast")
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>

#include <atcoder/all>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, n) for (i64 i = 0; i < (i64)(n); ++i)
#define reps(i, s, n) for (i64 i = s; i < (i64)(n); ++i)

void solve() {
    int n, q;
    cin >> n >> q;
    atcoder::dsu d(n);

    int t, u, v;
    while (q--) {
        cin >> t >> u >> v;
        if (t == 0) {
            d.merge(u, v);
        } else {
            if (d.same(u, v)) {
                cout << "1\n";
            } else {
                cout << "0\n";
            }
        }
    }
}
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    // cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    string s[N];
    int t[N];
    string X;
    bool isStart = false;

    for(int i; i<N; i++)cin >> s[i] >> t[i];
    cin >> X;

    int ans = 0;
    for(int i=0;i<N; i++){
        if(isStart) ans += t[i];
        if(s[i] == X){
            isStart = true;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = Integer.parseInt(in.next());
		int m = Integer.parseInt(in.next());
		int[][] a = new int[n][m];
		int[] b = new int[m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				a[i][j] = Integer.parseInt(in.next());
			}
		}
		for (int i = 0; i < m; i++) {
			b[i] = Integer.parseInt(in.next());
		}
		int[] c = new int[n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				c[i] += a[i][j] * b[j];
			}
		}
		for (int i = 0; i < n; i++) {
			System.out.println(c[i]);
		}
	}
}	


Measured memory_bytes: 38940
// D - いろはちゃんとマス目

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
const int MOD = 1e9 + 7;

class Comb {
private:
	int MOD;
	long long* fac;
	long long* finv;
	long long* inv;
public:
	// 事前にテーブルを作成
	Comb(int MAX, int MOD) {
		this->MOD = MOD;

		fac = new long long[MAX + 1];
		finv = new long long[MAX + 1];
		inv = new long long[MAX + 1];

		fac[0] = fac[1] = 1;
		finv[0] = finv[1] = 1;
		inv[1] = 1;
		for (int i = 2; i <= MAX; i++) {
			fac[i] = fac[i - 1] * i % MOD;
			inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
			finv[i] = finv[i - 1] * inv[i] % MOD;
		}
	}

	~Comb() {
		delete[] fac, finv, inv;
	}

	// 二項係数計算
	long long calc(int n, int k){
		if (n < k) return 0;
		if (n < 0 || k < 0) return 0;
		return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
	}
};

ll get_n_paths(int from_h, int from_w, int to_h, int to_w, Comb& comb) {
	int dh = to_h - from_h;
	int dw = to_w - from_w;
	return comb.calc(dh + dw, dh);
}

int main() {
	int H, W, A, B;
	cin >> H >> W >> A >> B;

    Comb comb = Comb(H + W, MOD);

    ll ans = 0;
    for (int i=B; i<W; i++) {
    	ans += get_n_paths(0, 0, H - A - 1, i, comb) * get_n_paths(H - A, i, H - 1, W - 1, comb);
    	ans %= MOD;
    }

    cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4992
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列
#define CO(a, b, c) ((a) ? (b) : (c))
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
typedef long long ll;

int main(void)
{
    int n, k;
    cin >> n >> k;

    vector<int> p(n);
    for (auto &&i : p)
    {
        cin >> i;
    }
    sort(p.begin(), p.end());

    int ans = 0;
    for (int i = 0; i < k; i++)
    {
        ans += p[i];
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 3628
if __name__ == "__main__":
    parent, children, depths, sibling, heights = {}, {}, {}, {}, {}
    n = int(input())
    for _ in range(n):
        i, left, right = input().split()
        if left == "-1" and right == "-1":
            children[i] = None
            continue
        if left == "-1" or right == "-1":
            child = left if right == "-1" else right
            children[i] = [child]
        else:
            children[i] = [left, right]
        for child in children[i]:
            parent[child] = i
    
    root = (set(children) - set(parent)).pop()
    parent[root] = "-1"
    sibling[root] = "-1"
    
    def get_degree(i):
        if children[i] is None:
            return 0
        return len(children[i])

    def get_type(i):
        if parent[i] == "-1":
            return "root"
        if children[i] is None:
            return "leaf"
        return "internal node"
    
    def set_depth(i, depth):
        depths[i] = depth
        if children[i] is not None:
            for child in children[i]:
                set_depth(child, depth+1)

    def set_sibling(i, s):
        sibling[i] = s
        childs = children[i]
        if childs is not None:
            if len(childs) == 1:
                set_sibling(childs[0], "-1")
            else:
                set_sibling(childs[0], childs[1])
                set_sibling(childs[1], childs[0])
    
    def set_height(i):
        if children[i] is None:
            heights[i] = 0
            return 0
        childs = children[i]
        if len(childs) == 1:
            heights[i] = set_height(childs[0])+1
            return heights[i]
        heights[i] = max(set_height(childs[0]), set_height(childs[1]))+1
        return heights[i]

    set_depth(root, 0)
    set_sibling(root, "-1")
    set_height(root)
    for i in map(str, range(n)):
        print("node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}".format(i, parent[i], sibling[i], get_degree(i), depths[i], heights[i], get_type(i)))


Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int h,w;
  cin>>h>>w;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++){
      string str;
      cin>>str;
      if(str=="snuke") cout<<(char)('A'+j)<<i+1<<endl;
    }
 
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

int main() {
	int a;
	string s;
	cin >> a >> s;
	if (a >= 3200) cout << s << endl;
	else cout << "red" << endl;
}

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

using namespace std;

int main(void){
    int a, b;
    cin >> a >> b;
    int d, r;
    double f;

    d = a / b;
    r = a % b;
    f = double(a) / double(b);
    printf("%d %d %.8lf\n", d, r, f);

    return 0;
}


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

int count(int n)
{
    int res=0;
    while(n!=0)
    {
        res++;
        n/=10;
    }
    return res;
}
int32_t main()
{
    int n;
    cin>>n;
    int ans=INT_MAX;
    for(int i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
        
        ans=min(ans,max(count(i),count(n/i)));
        
        }
    }
    if(ans==INT_MAX)
    cout<<count(n)<<endl;
    else
    cout<<ans<<endl;

}

Measured memory_bytes: 3640
n = int(input())
h = list(map(int, input().split()))
ans = 'Yes'
for i in range(n):
  if i == 0:
    h[i] -= 1
  else:
    if h[i] > h[i-1]:
      h[i] -= 1
    elif h[i] < h[i-1]:
      ans = 'No'
      break
print(ans)

Measured memory_bytes: 63984
// D - String Formation
#include <bits/stdc++.h>
using namespace std;

int main(){
	string S; int Q; cin>>S>>Q;
	int st = Q, ed = st + S.size(), odd = 0;
	S = string(Q,'-') + S + string(Q,'-');
	while(Q--){
		int t; cin>>t;
		if(t==1) odd ^= 1;
		else{
			int f; char c; cin>>f>>c;
			S[odd ^ (f-1)? ed++: --st] = c;
		}
	}
	string ans = "";
	if(odd) for(int i=ed-1; i>st-1; --i) ans += S[i];
	else for(int i=st; i<ed; ++i) ans += S[i];
	cout<<ans<<endl;
}

Measured memory_bytes: 1872
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define maxs(x,y) x = max(x, y)
#define mins(x,y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int A, B;
    cin >> A >> B;

    cout << (B-1 + A-2) / (A-1) << endl;

    //cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "3", "3 4 5" ].solve == "pairwise coprime" );
	assert( [ "3", "6 10 15" ].solve == "setwise coprime" );
	assert( [ "3", "6 10 16" ].solve == "not coprime" );
}



import std.algorithm;
import std.conv;
import std.format;
import std.numeric;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	
	auto ps = ( 10 ^^ 3 ).primes;
	auto fs = new bool[ 1 + 10 ^^ 6 ];
	auto u = true;
	auto c = as.front;
	foreach( a; as )
	{
		auto uu = true;
		foreach( g; a.primefactorize( ps ).group )
		{
			if( fs[ g[ 0 ] ] ) uu = false;
			else               fs[ g[ 0 ] ] = true;
		}
		if( !uu ) u = false;
		c = gcd( c, a );
	}
	
	if(      u      ) return "pairwise coprime";
	else if( c == 1 ) return "setwise coprime";
	else              return "not coprime";
}

// 素数列
auto primes( long x )
{
	Appender!( long[] ) ps;
	if( x < 2 ) return ps.data;
	
	auto cs = new bool[]( x + 1 );
	ps ~= 2L;
	for( auto i = 3L; i * i < cs.length; i += 2 )
	{
		if( cs[ i ] ) continue;
		for( auto j = i; i * j < cs.length; j++ )
		{
			cs[ i * j ] = true;
		}
	}
	for( auto i = 3L; i < cs.length; i += 2 )
	{
		if( !cs[ i ] ) ps ~= i;
	}
	return ps.data;
}

// 素因数分解
auto primefactorize( long x, long[] ps )
{
	Appender!( long[] ) fs;
	if( x < 2 ) return fs.data;
	
	auto s = cast( long ) x ^^ 0.5L;
	foreach( p; ps )
	{
		if( s < p ) break;
		while( x % p == 0 )
		{
			x /= p;
			fs ~= p;
		}
		if( x < 2 ) break;
	}
	if( 2 <= x ) fs ~= x;
	return fs.data;
}


Measured memory_bytes: 47976
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
#include<stdio.h>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

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

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}

int main(){
    int N;
    cin >> N;
    int num=0;
    int L=0;
    string S;
    for(int i=1;i<=N;++i){
        string S=toString(i);
        L=S.length();
        if(L%2!=0) ++num;
    }
    cout << num;
    }

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

int main()
{
    ios::sync_with_stdio(false);
    int n,k;
    vector<int> line;
    char temp;
    cin >> n >> k;
    
    cin >> temp;
    line.push_back(temp);
    int happyGuy = 0;
    for(int i = 1; i < n; ++i)
    {
        cin >> temp;
        if(line[i - 1] == temp)
            ++happyGuy;
        line.push_back(temp);
    }

    cout << min(happyGuy + 2 * k, n - 1) << endl;
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
// atoi : atoi(str.c_str())
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  int n;
  cin >> n;
  vector<long> x(n);
  vector<long> y(n);
  vector<long> h(n);
  rep(i,n){
    cin >> x.at(i) >> y.at(i) >> h.at(i);
  }
  long cx,cy;
  long high;
  
  rep(i,101){
    rep(j,101){
      cx = i;
      cy = j;
      rep(k,n){
        high = h.at(k) + abs(cx-x.at(k)) + abs(cy-y.at(k));
        //cout << high << endl;
        bool ans = true;
        rep(l,n){
          long zero = 0;
          long tmp = max((high - abs(cx-x.at(l)) - abs(cy-y.at(l))),zero);
          if(tmp != h.at(l)){
            ans = false;
            break;
          }
        }
        if(ans){
          cout << cx << " " << cy << " " << high << endl;
          return 0;
        }
      }
    }
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define md 1000000007
#define ll long long 
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fastmap mp.reserve(1024);mp.max_load_factor(0.25);
#define fastset st.reserve(1024);st.max_load_factor(0.25);

//freopen("inp.txt",r,stdin);
//freopen("out.txt",w,stdout);
ll int mpw(ll int a,ll int b,ll int m)
{
	ll int ans=1;
	if(a==0)return 0;
	if(a==1 || b==0)return 1;
	while(b)
	{
		if(b&1)
		{
			ans=(ans*a)%m;
		}
		a=(a*a)%m;
		b>>=1;
	}
	return ans;
}
 
ll int pw(ll int a,ll int b)
{
	ll int ans=1;
	if(a==0)return 0;
	if(a==1 || b==0)return 1;
	while(b)
	{
		if(b&1)
		{
			ans*=a;
		}
		a*=a;
		b>>=1;
	}
	return ans;
}
 
ll int mn(ll int a,ll int b)
{
	if(a<=b)
	{
		return a;
	}
	return b;
}
 
ll int mx(ll int a,ll int b)
{
	if(a>=b)
	{
		return a;
	}
	return b;
}

int main()
{
	fio
	int n;
	cin>>n;
	vector<pair<pair<int,int>,ll int>>nm(n);
	for(int i=0;i<n;++i)
	{
		cin>>nm[i].first.first>>nm[i].first.second>>nm[i].second;
	}
	sort(nm.begin(),nm.end(),[&](pair<pair<int,int>,ll int>l,pair<pair<int,int>,ll int>r)->bool{
		return l.first.first+l.first.second<r.first.first+r.first.second;
	});
	vector<ll int>D(22222,0);
	ll int ans=0;
	for(int i=0;i<n;++i)
	{
		vector<ll int>tmp=D;
		for(int j=0;j<=(nm[i].first.second);++j)
		{
			tmp[j+nm[i].first.first]=max(tmp[j+nm[i].first.first],D[j]+nm[i].second);
			ans=mx(ans,D[j]+nm[i].second);
		}
		D=tmp;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3824
#include <iostream>

using namespace std;

int main()
{
    long long n,a=1,sum=0;
    cin  >> n  ;
    while(a <=n)
    {
        if(a%3==0 && a%5==0)
        {
            a++;
        }
        else if(a%3==0)
            a++;
        else if(a%5==0)
            a++;
        else
        {
            sum=sum+a;
          //  cout<<a <<" "<<sum<<endl;
            a++;
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    string s;
    cin >> s;
    int l,r;
    rep(i,s.size()) {
        if(s[i] == 'A') {
            l = i;
            break;
        }
    }
    for(int i = s.size()-1; i >= 0; i--) {
        if(s[i] == 'Z') {
            r = i;
            break;
        }
    }
    cout << r-l+1 << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>

#define INF 1111111111

int cmp(const void* x, const void* y) {
	int a = *(const int*)x, b = *(const int*)y;
	return a < b ? -1 : a > b;
}

int L, n;
int P[1024], D[1024], T[1024];

int siraisiharuka;
int tomatu;
int sumipe[123456];

int mareitaso(int mimorinn) {
	int l = 0, r = tomatu - 1;
	while (l <= r) {
		int m = l + (r - l) / 2;
		if (sumipe[m] == mimorinn) return m;
		else if (sumipe[m] < mimorinn) l = m + 1;
		else r = m - 1;
	}
	exit(2);
	return 0;
}

struct edge_t {
	int to, cost;
};

int edgeCount[123456];
struct edge_t* edges[123456];

void addEdge(int from, int to, int cost) {
	int* c = edgeCount + from;
	struct edge_t** e = edges + from;
	struct edge_t* ne = realloc(*e, sizeof(**e) * (*c + 1));
	if (ne == NULL) exit(3);
	ne[*c].to = to;
	ne[*c].cost = cost;
	(*c)++;
	*e = ne;
}

int minCost[123456];
char kakutei[123456];

int main(void) {
	int i;
	if (scanf("%d%d", &L, &n) != 2) return 1;
	sumipe[siraisiharuka++] = 0;
	sumipe[siraisiharuka++] = L;
	for (i = 0; i < n; i++) {
		if (scanf("%d%d%d", &P[i], &D[i], &T[i]) != 3) return 1;
		sumipe[siraisiharuka++] = P[i];
		sumipe[siraisiharuka++] = P[i] + D[i];
	}
	qsort(sumipe, siraisiharuka, sizeof(*sumipe), cmp);
	tomatu = 1;
	for (i = 0; i < siraisiharuka; i++) {
		if (sumipe[tomatu - 1] != sumipe[i]) {
			sumipe[tomatu++] = sumipe[i];
		}
	}
	for (i = 1; i < tomatu; i++) {
		addEdge(i - 1, i, sumipe[i] - sumipe[i - 1]);
	}
	for (i = 0; i < n; i++) {
		addEdge(mareitaso(P[i]), mareitaso(P[i] + D[i]), T[i]);
	}
	for (i = 0; i < tomatu; i++) {
		minCost[i] = INF;
		kakutei[i] = 0;
	}
	minCost[mareitaso(0)] = 0;
	for (;;) {
		int minNode = -1;
		int minNodeCost = INF;
		for (i = 0; i < tomatu; i++) {
			if (!kakutei[i] && minCost[i] < minNodeCost) {
				minNode = i;
				minNodeCost = minCost[i];
			}
		}
		if (minNode < 0) break;
		kakutei[minNode] = 1;
		for (i = 0; i < edgeCount[minNode]; i++) {
			struct edge_t e = edges[minNode][i];
			if (minCost[e.to] > minCost[minNode] + e.cost) {
				minCost[e.to] = minCost[minNode] + e.cost;
			}
		}
	}
	printf("%d\n", minCost[mareitaso(L)]);
	return 0;
}



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

int main(){
    int n;
    string a, b, c;
    cin >> n >> a >> b >> c;

    int ans = 0;
    for(int i = 0; i < n; i++){
        map<char,int> m;
        m[a[i]]++, m[b[i]]++, m[c[i]]++;
        int z = 0;
        for(auto p : m){
            z = max(z, p.second);
        }
        ans += 3-z;
    }

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

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

int main() {
    list<int>L; int n, x; char s[15];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s;
        if (s[0] == 'i')cin >> x,  L.push_front(x);
        else if (s[6] == 'F')L.pop_front();
        else if (s[6] == 'L')L.pop_back();
        else {
            cin >> x;
            for (list<int>::iterator it = L.begin(); it != L.end(); it++)
                if (*it == x) {
                    L.erase(it); break;
                }
        }

    }
    n = 0;
    for (list<int>::iterator it = L.begin(); it != L.end(); it++) {
        if (n++)cout << " ";
        cout << *it;
    }
    cout << endl;
    return 0;
}



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

int n;
vector<string> str;
vector<int> cntDot;
vector<int> checked;

void dfs(int dotn){
	str[dotn][cntDot[dotn]-1] = '+';
	checked[dotn] = 1;
	//???????????????????????¢?´¢
	for (int i = dotn + 1; i < n; i++){
		if (cntDot[dotn] < cntDot[i] && checked[i] != 1) dfs(i); //?????????????????????dfs????????????
		if (cntDot[dotn] > cntDot[i]) break; //????????????????????????????????£??????break
		//????????????????????????'|'??§??????
		if (cntDot[dotn] == cntDot[i]){
			//'.'???'|'????????????
			if (cntDot[dotn] - 1 >= 0){
				for (int j = dotn+1; j < i; j++){
					str[j][cntDot[dotn] - 1] = '|';
				}
			}
			break;
		}
	}
}

int main(){
	while (cin >> n && n){
		str = vector<string>(n);
		cntDot = vector<int>(n);
		checked = vector<int>(n);
		for (int i = 0; i < n; ++i){
			cin >> str[i];
			//??????????????°?????°??????
			for (int j = 0; j < str[i].length();++j){
				if (str[i][j] == '.'){
					++cntDot[i];
					str[i][j] = ' ';
				}
				else{
					break;
				}
			}
		}
		for (int i = 1; i < n; i++){
			dfs(i);
		}
		for (int i = 0; i < n; i++){
			cout << str[i] << endl;
		}
		str.clear();
		cntDot.clear();
	}
	return 0;
}

Measured memory_bytes: 2064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
	ll N, M;
	cin >> N >> M;
	priority_queue<pair<int,int>> que;

	for (int i = 0; i < N; ++i)
	{
		int a;
		cin >> a;
		que.push(make_pair(a, 1));
	}

	for (int i = 0; i < M; ++i)
	{
		int b, c;
		cin >> b >> c;
		que.push(make_pair(c, b));
	}
	
	ll Ans = 0;
	for (int i = 0; i < N; ++i)
	{
		auto p = que.top();
		que.pop();
		Ans += p.first;
		
		if(p.second > 1)
		{
			--p.second;
			que.push(p);
		}
	}

	cout << Ans << endl;

}

Measured memory_bytes: 2420