akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;

int train[500][500];
int sum[501][501]; 
int main() {
  int n,m,q;
  cin >> n >> m >> q;
  int l, r;
  rep(i,m) {
    cin >> l >> r;
    l--; r--;
    train[l][r]++;
  }

  rep(i,n) rep(j,n) {
    sum[i+1][j+1]=sum[i+1][j]+sum[i][j+1]-sum[i][j]+train[i][j];
  }

  int x,y;
  rep(i,q) {
    cin >> x >> y; x--;
    int now = sum[y][y]-sum[x][y]-sum[y][x]+sum[x][x];
    cout << now << endl;
  }
  return 0;
}

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

int main(){
  string s;
  cin >> s;
  int res = 0;
  int c1 = 0, c0 = 0;
  int n = sz(s);
  for (int i = 0; i < n; i++) {
    if (s[i] == '0') c0++;
    else c1++;
  }
  cout << min(c1, c0) * 2 << endl;
  return 0;
} 

Measured memory_bytes: 512
n = int(input())
t = list(map(int, input().split()))
m = int(input())
p = [0] * m
x = [0] * m
for i in range(m):
    p[i], x[i] = map(int, input().split())

ans = sum(t)
for i in range(m):
    print(ans - t[p[i]-1] + x[i])

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline
from collections import defaultdict
n = int(input())
a = [list(map(int,input().split())) for i in range(n)]
mod = 10**9+7
def p2(x):
  return pow(2,x,mod)
dc = defaultdict(int)
st = set()
from math import gcd
n00 = 0
n0x = 0
nx0 = 0
nxy = 0
ls = []
for i in range(n):
  if a[i][0] == a[i][1] == 0:
    n00 += 1
  elif a[i][0] == 0:
    n0x += 1
  elif a[i][1] == 0:
    nx0 += 1
  else:
    nxy += 1
    if a[i][0] < 0 and a[i][1] < 0:
      a[i][0] *= -1
      a[i][1] *= -1
    elif a[i][0] < 0:
      a[i][0] *= -1
      a[i][1] *= -1
    ls.append(a[i])
if len(ls) == 0:
  print((p2(n0x)+p2(nx0)-1+n00-1)%mod)
  exit()
def part(x,y):
  g = gcd(x,y)
  return (x//g,y//g)
for i in range(nxy):
  p = part(*ls[i])
  st.add(p)
  dc[p] += 1
banned = []
for i,j in dc:
  if i*j > 0 and (j,-i) in st:
    banned.append((dc[(i,j)],dc[(j,-i)]))
sm = sum([banned[i][0]+banned[i][1] for i in range(len(banned))])
ans = p2(nxy-sm)
for i,j in banned:
  ans = (ans*(p2(i)+p2(j)-1))%mod
k = p2(n0x)+p2(nx0)-1
ans *= k
ans += n00-1
print(ans%mod)

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

int main(){
    int n;
    string s;
    cin >> n >> s;
    if(n%2){
        cout <<"No" <<endl;
        return 0;
    }
    string t = s.substr(0,n/2);
    string u = s.substr(n/2,n/2);
  
    if(t==u){
        cout <<"Yes" <<endl;
    }else{
        cout <<"No" <<endl;
    }
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let A: usize = sc.get();
    let B: f64 = sc.get();
    let B = (B * 100. + 0.05).floor() as usize;
    let ans = (A * B) / 100;
    println!("{}", ans);
}


Measured memory_bytes: 2660
N = int(input())
S = input()
import re
def nchars(s, n):
    """文字列 s に、同じ文字が n 個以上連続している部分文字列を見つける
    """
    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1))  # カンマを取ると n 個ちょうどになる
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]

print(len(list(nchars(S, 1))))


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

using namespace std;

void hawawa()
{
	int n;
	long long x;
	cin >> n >> x;
	vector<long long> a(n);
	for (auto&& i : a) {
		cin >> i;
	}
	long long ans = accumulate(begin(a), end(a), 0LL);
	vector<long long> b = a;
	for (int i = 1; i < n; i++) {
		for (int j = 0; j < n; j++) {
			b[j] = min(b[j], a[(j + n - i) % n]);
		}
		ans = min(ans, accumulate(begin(b), end(b), 0LL) + i * x);
	}
	cout << ans << "\n";
}

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


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int a, b;
    cin >> a >> b;
    if(a > 0){
        cout << "Positive" << endl;
    }else if(a == 0 || b == 0 || (a < 0 && b > 0)){
        cout << "Zero" << endl;
    }else if((abs(a) - abs(b) + 1) % 2 == 0){
        cout << "Positive" << endl;
    }else{
        cout << "Negative" << endl;
    }
    return 0;
}


Measured memory_bytes: 892
k = int(input())
x, y = map(int, input().split())
ans = []
if k % 2 == 0:
    if (x + y) % 2 == 1:
        print(-1)
        exit()
x_reverse = False
y_reverse = False
if x < 0:
    x *= -1
    x_reverse = True
if y < 0:
    y *= -1
    y_reverse = True


def app(a, b):
    global ans
    if x_reverse:
        a *= -1
    if y_reverse:
        b *= -1

    ans.append((a, b))


nowx = 0
nowy = 0

while abs(x - nowx) + abs(y - nowy) >= 2 * k:
    if abs(x - nowx) > k:
        nowx += k
    else:
        nowy += k
    app(nowx, nowy)


def ok():
    app(x, y)
    print(len(ans))
    for a, b in ans:
        print(a, b)
    exit()


rest = abs(x - nowx) + abs(y - nowy)
if rest == k:
    ok()

if rest % 2 == 0:
    delta = 2 * k - rest
    assert delta % 2 == 0
    if abs(x - nowx) < abs(y - nowy):
        temp = abs(x - nowx) + delta // 2
        nowx += temp
        nowy += k - temp
    else:
        temp = abs(y - nowy) + delta // 2
        nowy += temp
        nowx += k - temp
    app(nowx, nowy)
    ok()

# 残りが奇数のときは、条件から一旦ゴールをすぎる方向に移動すれば、
# 残りの距離の偶奇が変わる。

if abs(x - nowx) < abs(y - nowy):
    nowx += k
    app(nowx, nowy)
else:
    nowy += k
    app(nowx, nowy)

x_delta = x - nowx
x_pm = x_delta // abs(x_delta)
y_delta = y - nowy
y_pm = y_delta // abs(y_delta)
if abs(x_delta) < abs(y_delta):
    delta = 2 * k - (abs(x_delta) + abs(y_delta))
    temp = abs(x - nowx) + delta // 2
    nowx += x_pm * temp
    nowy += y_pm * (k - temp)
    app(nowx, nowy)
    ok()
else:
    delta = 2 * k - (abs(x_delta) + abs(y_delta))
    temp = abs(y - nowy) + delta // 2
    nowy += y_pm * temp
    nowx += x_pm * (k - temp)
    app(nowx, nowy)
    ok()



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

using namespace std;

int c[111];
int main() {
	int n;
	cin >> n;
	list<int> l;
	for (int i = 0; i < n; i++) {
		int b;
		cin >> b;
		l.push_back(b);
	}
	for (int i = n; i--;) {
		int k = i + 1;
		auto j = l.end();
		for (; j != l.begin(); k--)
			if (*--j == k) goto p;
		cout << -1 << endl;
		return 0;
	p:
		l.erase(j);
		c[i] = k;
	}
	for (int i = 0; i < n; i++)
		cout << c[i] << '\n';
	cout << flush;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#define ll long long
#define inf  1000000007
#define pa pair<int,int>
using namespace std;

ll po(ll m,ll n){
ll k;
if(n==1) k= m%inf;
else if(n%2==0) k= (po(m,n/2)*po(m,n/2))%inf;
else  k=(m*(po(m,n-1)%inf))%inf;
//cout<<m<<" "<<n<<" "<<k<<endl;

return k;
}

int main(){
ll m,n;
cin>>m>>n;
cout<<po(m,n)<<endl;

return 0;
}

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

int main(void){
  int count;
  int n,i;
  int x[50],y[50];
  double s;

  count=0;
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    count++;
    s = 0;
    for(i=0;i<n;i++)scanf("%d %d",&x[i],&y[i]);

    for(i=1;i<n-1;i++){
      s += ( (x[i+1]-x[0])*(y[i]-y[0]) - (y[i+1]-y[0])*(x[i]-x[0]) )/2.0;
    }

    printf("%d %1.1lf\n",count,s);
  }
  return 0;

}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

/////////////////////////////////////////////////////////////
class ModuloOperator {
 public:
  ll modulo;

  ModuloOperator(ll modulo) {
    this->modulo = modulo;
  }

  ll add(ll a, ll b) {
    ll ret = a + b;
    ret %= modulo;
    return ret;
  }

  ll sub(ll a, ll b) {
    ll ret = a - b;
    if (ret < 0)
      ret += modulo;
    else
      ret %= modulo;
    return ret;
  }

  ll mul(ll a, ll b) {
    ll ret = a * b;
    ret %= modulo;
    return ret;
  }

  ll div(ll a, ll b) { return mul(a, pow(b, modulo - 2)); }

  ll pow(ll x, ll y) {
    ll res = 1LL;

    x %= modulo;

    while (y > 0) {
      if (y & 1) {
        res = mul(res, x);
      }

      y = y >> 1;
      x = mul(x, x);
    }

    return res;
  }
};
/////////////////////////////////////////////////////////////

const ll MOD = (ll)(1e9 + 7);

ModuloOperator mo(MOD);

ll x, y;

pair<ll, ll> do_convert(ll bx, ll by) {
  ll nx = 2LL * bx + (-1LL) * by;
  ll ny = (-1LL) * bx + 2LL * by;

  return make_pair(nx, ny);
}

int main(void) {
  // Here your code !
  scanf("%lld %lld", &x, &y);

  auto nxy = do_convert(x, y);

  ll nx = nxy.first;
  ll ny = nxy.second;

  if (nx < 0 || ny < 0 || nx % 3LL != 0 || ny % 3LL != 0) {
    printf("0\n");
    return 0;
  }

  nx /= 3LL;
  ny /= 3LL;

  ll n = nx + ny;

  ll top = 1LL;
  for (ll i = 1LL; i <= n; ++i) {
    top = mo.mul(top, i);
  }

  ll gnx = 1LL;
  for (ll i = 1LL; i <= nx; ++i) {
    gnx = mo.mul(gnx, i);
  }

  ll gny = 1LL;
  for (ll i = 1LL; i <= ny; ++i) {
    gny = mo.mul(gny, i);
  }

  ll bottom = mo.mul(gnx, gny);

  ll ans = mo.div(top, bottom);

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
int main() {
    int64_t K;
    cin >> K;
    queue<int64_t> q({1, 2, 3, 4, 5, 6, 7, 8, 9});
    for (int64_t i = 0; i < K - 1; i++) {
        int64_t t = q.front(), u = t % 10;
        q.pop();
        if (u > 0) q.push(10 * t + u - 1);
        q.push(10 * t + u);
        if (u < 9) q.push(10 * t + u + 1);
    }
    cout << q.front() << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

const int INF = 1e9+5;
const ll LINF = 1e18;

ll gcd(ll a,ll b){
  return b ? gcd(b,a%b) : a;
}

int main(){
  int n;
  ll x;
  cin >> n >> x;
  vector<ll> X(n);
  vector<ll> l(n);
  rep(i,n) {
    cin >> X[i];
    l[i] = abs(X[i]-x);
  }
  ll g = l[0];
  for(int i=1;i<n;i++){
    g = gcd(g,l[i]);
  }
  cout << g <<endl;

}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;
#include <map>
#include <math.h>
 
using ll = long long;
using namespace std;

ll n, k;
const ll mod = 1000000007;

int main(){
    string c1, c2;
    cin >> c1 >> c2;
    if(c1[0]==c2[2]&&c1[2]==c2[0]&&c1[1]==c2[1]) out("YES");
    else out("NO");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> b(n - 1); for (auto&& e : b) cin >> e;
  int res = 0;
  for (int i = 0; i < n; ++i) {
    int mn = 1e9;
    if (i < n - 1) mn = min(mn, b[i]);
    if (i) mn = min(mn, b[i - 1]);
    res += mn;
  }
  cout << res << '\n';
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string s;
	int f=0,i;
	cin>>s;
	for(i=0;i<s.size();i++)
	{
	if(s[i]=='C')f=1;
	if(f!=0&&s[i]=='F') f=-1;
	}
	if(f==-1) cout<<"Yes";
	else cout<<"No";
	return 0;
 } 

Measured memory_bytes: 256
import std.stdio;
import std.array;
import std.conv;
import std.string;
import std.algorithm;
import core.stdc.string;

int table[11][1 << 10][350];

uint solve(uint set, uint n, uint s, uint curr, uint index) {
  if (n <= 10 && curr <= 350 && table[n][set][curr] >= 0) return cast(uint)table[n][set][curr];
  if (curr > s) return 0;
  if (n == 0) {
    if (curr == s) return 1;
    else return 0;
  }
  uint sum = 0;
  for(int i = 0; i <= 9; i++) {
    if (((set >> i) & 1) == 0) {
      sum += solve(set | (1 << i), n - 1, s, curr + index * i, index + 1);
    }
  }
  table[n][set][curr] = sum;
  return sum;
}

void main() {
  while(true) {
    string line = readln.chomp;
    memset(cast(void*)table, -1, table.sizeof);
    if (stdin.eof) break;
    uint[] data = line.split(" ").map!(to!(uint)).array;
    solve(0, data[0], data[1], 0, 1).writeln;
  }
}

Measured memory_bytes: 16480
#include <iostream>

using namespace std;

int main()
{
   string a;
   cin>>a;
   if(a=="Sunny"){
       cout<<"Cloudy";
   }
   else if(a=="Cloudy"){
       cout<<"Rainy";
   }
   else if(a=="Rainy"){
       cout<<"Sunny";
   }
   
   return 0;
}

Measured memory_bytes: 256
/**
 *    Author:  "Robin Singh" !!!!    
**/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define str string 
#define szz(v) ((int)(v).size())  
#define vi vector<int>
#define vll vector<ll>
#define fr(i, j, k) for(i = j; i < k; i++)
#define bk(i, j, k) for(i = j; i >= k; i--)
#define frit(it, a) for(__typeof((a).begin()) it = a.begin(); it != a.end(); ++it)
#define mem(ptr)  memset(ptr, 0, sizeof ptr)  // use fill() for value other than 0 //
#define rtn return 
#define time fprintf(stderr, "\nTIME = %lf\n", 1.0 * clock()/CLOCKS_PER_SEC)
#define nl "\n"
#define INF 1LL<<61
#define inf 1<<30
#define dbg(x) (cerr << #x << ": " << x << "\n")
const long long mod = 1e9+7;

ll gcd(ll a,ll b) { return b==0 ? a : gcd(b, a%b); }
ll expo(ll x, ll y){ ll res = 1; x = x % mod;  while (y > 0) { if (y & 1)res = (res*x) % mod; y = y>>1;x = (x*x) % mod;}return res;}
void matmul(ll a[][2], ll b[][2]) { ll tmp[2][2]; for(int i=0; i<2; i++) { for(int j=0; j<2; j++) { tmp[i][j] = 0; for(int k=0; k<2; k++) tmp[i][j] = (tmp[i][j] + a[i][k]*b[k][j]) % mod; }} for(int i=0; i<2; i++) for(int j=0; j<2; j++) a[i][j] = tmp[i][j]; }
ll fibo(int n)    // returns nth fibonacci number, also S(n) = f(n+2)-1
{ if(n == 0) return 0; else if(n == 1) return 1; ll T[2][2] = { {0, 1} , {1, 1} }; ll res[2][2] = { {1, 0}, {0,1} }; n--; while(n) { if(n & 1) matmul(res, T); n >>= 1; matmul(T, T); } return res[1][1]; }

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n;
    cin >> n;
    if(n <= 999) cout << "ABC";
    else cout << "ABD";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int h, n, total=0;
    cin>>h>>n;
    int a[n];
    for(int i=0;i<n;i++)
     {
         cin>>a[n];
         total=total+a[n];
     }
     if(total>=h)
        cout<<"Yes"<<endl;
     else
        cout<<"No"<<endl;
     return 0;
}




Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		List<Integer> unko=new ArrayList<Integer>();
		fra(N,unko);
		HashSet<Integer> buri=new HashSet<Integer>();
		for(int i=0; i<unko.size(); i++) {
			int a=unko.get(i);
			if(a!=1) {
				buri.add(a);
			}
		}
		long aa=N;
		Iterator<Integer> bubu = buri.iterator();
		for(int i=0; i<buri.size(); i++) {
			long tmp=(long) bubu.next();
			aa=aa*(tmp-1)/tmp;
		}
		System.out.println(aa);
	}
	public static void fra(int a,List<Integer> p) {//int型用
		for(int i=2; i*i<=a; i++) {
			if(a%i==0) {
				p.add(i);
				fra(a/i,p);
				return;
			}
		}
		p.add(a);
	}

	public static void fra(long a,List<Long> p) {//long型用
		for(long i=2; i*i<=a; i++) {
			if(a%i==0) {
				p.add(i);
				fra(a/i,p);
				return;
			}
		}
		p.add(a);
	}
}


Measured memory_bytes: 26248
#include <iostream>
#include <algorithm>
#include <cstring>

#define ll long long 

using namespace std;

int n, w;
ll dp[105][100050];
ll V[105], W[105];

ll solve(int i, int v){
  if(v < 0)
    return 10000000000ll;
    
  if(i == n){
    if(v == 0)
      return 0;
    else
      return 10000000000ll;
  }
  
  if(dp[i][v] != -1)
    return dp[i][v];
  
  return dp[i][v] = min(W[i] + solve(i + 1, v - V[i]), solve(i + 1, v));
} 

int main()
{
    int max_v = 0;

    cin >> n >> w;

    memset(dp, -1, sizeof dp);

    for(int i = 0; i < n; i++)
      cin >> W[i] >> V[i];
    
    // Encontrando o valor máximo possível
    for(int i = 0; i < n; i++)
      max_v += V[i];

    ll ans = 0;
    for(ll i = 0; i <= max_v; i++){
      if(solve(0, i) <= w)
        ans = max(ans, i);
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 85696
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
int a,b[210000],c[210000],d ;
cin>>a;
for(int i=0;i<a;i++){
  cin>>b[i];
  c[i]=b[i];
     }
  sort(c,c+a,greater<int>());
    for(int i=0;i<a;i++){
    if(b[i]==c[0]){cout<<c[1];}
    else cout<<c[0];
      cout<<endl;
    }
}


Measured memory_bytes: 3200
H,W=map(int,input().split())
c=[list(map(int,input().split())) for i in range(10)]

INF=10**10
tmp=[[INF]*10 for i in range(10)]
for k in range(9):
    for i in range(10):
        for j in range(10):
            tmp[i][j]=min(c[i][k]+c[k][j] for k in range(10))
            c[i][j]=min(tmp[i][j],c[i][j])

count=[0]*10
for i in range(H):
    l=list(map(int,input().split()))
    for j in range(10):
        count[j]+=l.count(j)
ans=0
for i in range(10):
    ans+=count[i]*c[i][1]

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <stack>
#include <algorithm>

using namespace std;

int main(){
    int n;
    long long ans = 0;
    int a[100000] = {}, b[100000] = {}, c[100000] = {};
    stack<int> st;

    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        cin >> b[i];
    }
    for(int i = 0; i < n; i++){
        cin >> c[i];
    }
    sort(a, a+n);
    sort(b, b+n);
    sort(c, c+n);
    int bi = n-1;
    bool flag = true;
    int ai = n-1;
    int ar_bi[100000] = {};
    while(flag){
        if(a[ai] < b[bi]){
            ar_bi[bi] = ai+1;
            if(bi > 0) --bi;
            else    break;
        }
        else{
            if(ai > 0) --ai;
            else{
                break;
            }
        }
    }
    int ci = n-1;
    bi = n-1;
    long long ar_sum[100000] = {};
    ar_sum[0] = ar_bi[0];
    for(int i = 1; i < n; i++){
        ar_sum[i] = ar_sum[i-1] + ar_bi[i];
    }
    while(true){
        if(c[ci] > b[bi]){
            ans += 1LL * ar_sum[bi];
            if(ci > 0) --ci;
            else    break;
        }
        else{
            if(bi > 0)  --bi;
            else    break;
        }
    }

    cout << ans << '\n';
}

Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


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

    int n;
    cin >> n;
    vs64 x(n);
    vs64 a(n), b(n);
    rep (i, n) cin >> a[i];
    rep (i, n) cin >> b[i];
    rep (i, n) x[i] = a[i] - b[i];
    sort(x.begin(), x.end());

    int l = 0;
    int r = n - 1;
    enum {
        BLACK = 2,
        GRAY  = 1,
        WHITE = 0
    };
    vs32 color(n, WHITE);
    while (x[l] < 0 && x[r] > 0)
    {
        s64 temp = x[r] + x[l];
        if (temp >= 0)
        {
            x[r] = temp;
            x[l] = 0;
            color[r] = GRAY;
            color[l] = BLACK;
            ++l;
        }
        else
        {
            x[r] = 0;
            x[l] = temp;
            color[r] = BLACK;
            color[l] = GRAY;
            --r;
        }
    }

    int ans = 0;
    if (x[l] >= 0)
    {
        rep (i, n)
        {
            if (color[i] != WHITE) ++ans;
        }
    }
    else
    {
        ans = -1;
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 2944
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)


def main():
    a = list(map(int, input().split()))
    b = -inf
    for i in range(2):
        for j in range(2, 4):
            b = max(b, a[i] * a[j])
    print(b)
main()


Measured memory_bytes: 9476
#include<bits/stdc++.h>
#include<string>
typedef long long ll;
const int mod = 1e9 + 7;
using namespace std;

void solve() {
	int n, m, k;
	cin >> n >> m >> k;
	vector<ll> a(n + 1, 0), b(m + 1, 0);
	for(int i = 1; i <=  n; ++i) {
		cin >> a[i];
		a[i] += a[i - 1];
		}
		for(int i = 1; i <= m; ++i) {
			cin >> b[i];
			b[i] += b[i - 1];
			}
			ll ans = -1e18, j = 0;
	for(int i = n; i >= 0; --i) {
		int t = k;
		if(a[i] > k) continue;
		k -= a[i];
		while(k - b[j] > 0 && j <= m) {
			if(k - b[++j] < 0 || j > m) {
				--j;
				break;
				}
			}
			ans = max(ans, i + j);
			k = t;
		}
		cout << ans << endl;
}
 
int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.precision(20);
		solve();
	return 0;
}
 
 
 


Measured memory_bytes: 6352
import sys
input = sys.stdin.buffer.readline

H, W, D = map(int, input().split())
grid = []
for _ in range(H):
    grid.append(list(map(int, input().split())))

place = [0] * (H*W+1)
for i in range(H):
    for j in range(W):
        place[grid[i][j]] = (i, j)
cs = [0] * (H*W+1)
for i in range(1, H*W+1):
    if i - D > 0:
        cs[i] = cs[i-D] + abs(place[i][0] - place[i-D][0]) + abs(place[i][1] - place[i-D][1])

Q = int(input())
for _ in range(Q):
    a, b = map(int, input().split())
    print(cs[b] - cs[a])


Measured memory_bytes: 55428
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c;
  char d, e;
  
  cin >> a >> d >> b >> e >>c;
  
  if (b >= 5){
    cout << "TBD" << endl;
  }
  else{
    cout << "Heisei" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define int long long
#define ms_valtype pair
#define inf (int)(1e17)

typedef struct {
	int H;
	int P;
}pair;

//比較関数
int compare_ms(ms_valtype a, ms_valtype b){
	return (a.H + a.P) - (b.H + b.P);
}

//昇順
void sort_sub(ms_valtype *origin, int left, int right, ms_valtype *tmp){
	if(right - left > 1){
		int i, j, k, half = (left + right) / 2;
		sort_sub(origin, left, half, tmp);
		sort_sub(origin, half, right, tmp);
		for(i = left; i < right; i++){
			tmp[i] = origin[i];
		}
		for(i = left, j = left, k = half; i < right; i++){
			if(k == right){
				origin[i] = tmp[j];
				j++;
			}
			else if(compare_ms(tmp[j], tmp[k]) <= 0 && j < half){
				origin[i] = tmp[j];
				j++;
			}
			else{
				origin[i] = tmp[k];
				k++;
			}
		}
	}
}

void sort(ms_valtype *origin, int N){
	ms_valtype *tmp = (ms_valtype *)malloc(sizeof(ms_valtype) * N);
	sort_sub(origin, 0, N, tmp);
	free(tmp);
}

int min(int a, int b){
	return a <= b ? a : b;
}

signed main(){
	int N, i, j;
	scanf("%lld", &N);
	pair *A = (pair *)malloc(sizeof(pair) * N);
	for(i = 0; i < N; i++){
		scanf("%lld%lld", &A[i].H, &A[i].P);
	}
	sort(A, N);
	int **dp = (int **)malloc(sizeof(int *) * (N + 1));
	for(i = 0; i <= N; i++){
		dp[i] = (int *)malloc(sizeof(int) * (N + 1));
		dp[i][0] = 0;
	}
	for(j = 1; j <= N; j++){
		dp[0][j] = inf;
	}
	for(i = 1; i <= N; i++){
		for(j = 1; j <= N; j++){
			dp[i][j] = dp[i - 1][j];
			if(dp[i - 1][j - 1] <= A[i - 1].H){
				dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + A[i - 1].P);
			}
		}
	}
	for(j = 1; j <= N; j++){
		if(dp[N][j] >= inf){
			printf("%lld\n", j - 1);
			return 0;
		}
	}
	printf("%lld\n", N);
	return 0;
}

Measured memory_bytes: 195712
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll chu(ll a,ll b,ll c)
{
	ll clen;
	if(a%c==0&&b%c==0)
	{
		clen=b/c-a/c+1;
	}
	else if(a%c!=0)
	{
		clen=b/c-a/c;
	}
	else if(b%c!=0)
	{
		clen=b/c-a/c+1;
	}
	else
	{
		clen=b/c-a/c;
	}
	return clen;
}
ll gcd(ll m,ll n)
{  
 	if (m < n)
	{
		ll tmp = m;
		m = n;
		n = tmp;
	}
	if (n == 0)
		return m;
	else
		return gcd(n,m % n);
}
int main()
{
	std::ios::sync_with_stdio(false);
	ll a,b,c,d;
	ll clen,dlen,cdlen;
	cin>>a>>b>>c>>d;
	clen=chu(a,b,c);
	dlen=chu(a,b,d);
	ll cd=(c*d)/gcd(c,d);
	cdlen=chu(a,b,cd);
	cout<<(b-a+1)-(clen+dlen-cdlen);
	return 0;
}

Measured memory_bytes: 256
n = int(input())
w = list(map(int, input().split()))
total = sum(w)
half = 0
k = n - 1
for i in range(n-1):
    if half + w[i] < total/2:
        half += w[i]
    else :
        k = i
        break
half_2 = half + w[k]
if k == n - 1 :
    print(total - 2 * half)
elif abs(total - 2 * half) > abs(total - 2 * half_2):
    print(abs(total - 2 * half_2))
else:
    print(abs(total - 2 * half))

Measured memory_bytes: 3064
a, b, c = map(int, input().split())
d1 = sorted([a,b,c])[2] - sorted([a,b,c])[0]
d2 = sorted([a,b,c])[2] - sorted([a,b,c])[1]
if abs(d1-d2) % 2 == 0:
  print(abs(d1-d2)//2 + min(d1,d2))
else:
  print((abs(d1-d2)+1)//2 + 1 + min(d1,d2))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lowbit(a) ((a)&-(a))
#define clean(a,b) memset(a,b,sizeof(a))
const int mod = 1e9 + 7;
const int inf=0x3f3f3f3f;
const int maxn = 1e6+9;

inline int read(){char c=getchar();int tot=1;while ((c<'0'|| c>'9')&&c!='-') c=getchar();if (c=='-'){tot=-1;c=getchar();}
int sum=0;while (c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}return sum*tot;}

int _;

//////////////////////////////////////////////////////////////////////////
ll vis[maxn],prime[maxn];
//////////////////////////////////////////////////////////////////////////
int main()
{
    ll n;
    scanf("%lld",&n);
    ll n_=sqrt(n),cnt=0;
    for(ll i=2;i<=n_;i++)
    {
        if(vis[i]) continue;
        prime[++cnt]=i;
        for(ll j=2;j<=n_/i;j++) vis[i*j]=1;
    }
    ll ans=0;
    for(ll i=1;i<=cnt;i++)
    {
        ll sum=0;
        ll pr=prime[i];
        while(n%pr==0)
        {
            n/=pr;
            sum++;
        }
        ll a=sqrt(sum*2);
        if(a*(a+1)>sum*2) a--;
        ans+=a;
    }
    if(n!=1) ans++;
    printf("%lld\n",ans);
    return 0;
}


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

int main() {
    int N, M, C;
    cin >> N >> M >> C;

    vector<int> A(M), B(M);
    for (int i=0; i<M; i++) cin >> B[i];

    int res, cnt = 0;
    for (int i=0; i<N; i++) {
        res = 0;
        for (int j=0; j<M; j++) {
            cin >> A[j];
            res += A[j] * B[j];
        }
        if (res+C > 0) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9+7);
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,1,-1};

ll gcd(ll a,ll b){
    if(a < b)swap(a, 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;
}

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

ll power(ll a, ll b){
    ll ans = 1;
    a %= mod;
    while(b) {
        if(b & 1LL) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}

//modの値の確認をすること
int main(){
    ll n;
    cin >> n;
    ll l = 0,r = n - 1;
    vector<ll> c(n,-1);
    string sl,sr,s;
    pf(l);
    cin >> sl;
    if(sl == "Vacant")return 0;
    pf(r);
    cin >> sr;
    if(sr == "Vacant")return 0;
    rep0(i,20){
        ll k = (r + l) / 2;
        pf(k);
        cin >> s;
        if(s == "Vacant")return 0;
        if((sl == s && (k - l) % 2 == 1) || (sl != s && (k - l) % 2 == 0)){
            r = k;
            sr = s;
        }else{
            l = k;
            sl = s;
        }
    }
    return 0;
}


Measured memory_bytes: 1620
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

fn main() {
    input! {
        n: usize,
        results: [String;n],
    }

    let mut count: HashMap<String, u64> = HashMap::new();

    for res in results {
        *count.entry(res).or_insert(0) += 1;
    }

    println!("AC x {}", count.get("AC").unwrap_or(&0));
    println!("WA x {}", count.get("WA").unwrap_or(&0));
    println!("TLE x {}", count.get("TLE").unwrap_or(&0));
    println!("RE x {}", count.get("RE").unwrap_or(&0));
}


Measured memory_bytes: 7872
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
  int n, k;
  cin >> n >> k;
  int res = 0;
  for(int i = 0; i < n; i++){
    int x;
    cin >> x;
    res += min(x, k - x) * 2;
  }
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
n = input()
def main(n):
    n = [0] + [int(i) for i in n] + [0]
    last = 0
    ans = 0
    last_5 = 0
    ls = []
    for i in n[::-1]:
        if i > 5:
            if last == 0 and last_5 == 0:
                ans += 10 - i
                ls.append(10 - i)
            else:
                ans += 10 - i - 1
                ls.append(10 - i - 1)
            last += 1 + last_5
            last_5 = 0
        elif i == 5:
            if last == 0 and last_5 == 0:
                ans += 5
                last = 0
                last_5 = 1
                ls.append(5)
            else:
                ans += 10 - 5  - 1
                last += 1 + last_5
                last_5 = 0
                ls.append(4)
        else:
            if last >= 1:
                if i == 4:
                    ans += 5
                    last = 0
                    last_5 = 1
                    ls.append(5)
                    continue
                else:
                    ans += 1 + i
                    ls.append(1 + i)
            else:
                ans += i
                ls.append(i)
            last = 0
            last_5 = 0
    print(ans)

if __name__ == '__main__':
    main(n)

Measured memory_bytes: 31656
/* 
	Author: ankrypt
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define all(x) x.begin(), x.end() 
#define ub upper_bound
#define lb lower_bound
#define MAX_INT 15
#define PI 3.141592653589793
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fi(a, b, c, d) for(int a = b; a < c; a += d)
#define fl(a, b, c, d) for(ll a = b; a < c; a += d)
#define fei(a, b, c, d) for(int a = b; a <= c; a += d)
#define fel(a, b, c, d) for(ll a = b; a <= c; a += d)
#define quit exit(0)
#define mem(x, a) memset(x, a, sizeof x)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pcl pair<char, ll>
#define psl pair<string, ll>


ll N, M, A, B, C;
ll arr[MAX_INT], arr1[MAX_INT], data[MAX_INT];
vector<ll> V;
unordered_map<ll, ll> mp;
set<ll> s;
string S = "";
ll cases;

int main() {
	go;
    cin >> N >> A >> B;
    ll val = N * 100 + A * 10 + B;
    if(val % 4) {
    	cout << "NO\n";
    } 
    else {
    	cout << "YES\n";
    }
    
	return 0;
}
/*
	Powered by Buggy Plugin
*/




Measured memory_bytes: 3632
/*
 * reverse porland
 * stack
 *
 *
 */
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

#define MAX 100
int stack[MAX+1],p;
void push(int);
int pop(void);
int isempty(void);

int main(){

    int before,after,j;
    char c[100];

    while(scanf("%s",c) != EOF){
        if(!strcmp(c,"+")){
            after = pop();
            before = pop();
            push(after + before);

        }else if(!strcmp(c,"-")){

            after = pop();
            before = pop(); 
            push(before - after);

        }else if(!strcmp(c,"*")){

            push(pop()*pop());

        }else if(!strcmp(c,"/")){

            after = pop();
            before = pop();

            push(before/after);
        }else{
            push(atoi(c));
        }

    }

    printf("%d\n",pop());
    return 0;
}

void push(int x){
    stack[p++]=x;
}

int pop(){
    if(isempty()){
        return stack[--p];
    }
    return 0;
}


int isempty(){
    if(stack[p]!='null'){
        return 1;
    }else{
        return 0;
    }
}



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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }



string s, t;
int b[26], bb[26];
int S[202020], T[202020];
void solve(){
	cin >> s >> t;
	int n = s.size();
	
	int cnt = 1;
	for(int i = 0; i < n; i++){
		if(b[s[i]-'a']){
			S[i] = b[s[i]-'a'];
			continue;
		}
		b[s[i]-'a'] = cnt;
		S[i] = cnt;
		cnt++;
	}
	cnt = 1;
	for(int i = 0; i < n; i++){
		if(bb[t[i]-'a']){
			T[i] = bb[t[i]-'a'];
			continue;
		}
		bb[t[i]-'a'] = cnt;
		T[i] = cnt;
		cnt++;
	}
	for(int i = 0; i < n; i++){
		if(S[i] != T[i]){
			cout << "No" << endl;
			return;
		}
	}
	cout << "Yes" << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 2452
# -*- coding: utf-8 -*-
ABC_str = input()
ABC_list = ABC_str.split(' ')
ABC_list.sort()
if ABC_list[0] == '5' and ABC_list[1] == '5' and ABC_list[2] == '7':
    print('{}'.format('YES'))
else:
    print('{}'.format('NO'))


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

using namespace std;

int main(){
  long N, W;
  cin >> N >> W;
  long w[N], v[N];
  long vmax = N * 1001;
  long wmax = 10000000000;

  // dp[i][j] : iまでの商品で、価値jを達成する重さの最小値
  // dp[i+1][j]: min(dp[i][j], dp[i][j-v[i+1]] + w[i+1])
  // O(10^3 * N * N) = 10^7 マス
  //
  // long dp[N][vmax];
  vector<vector<long> > dp(N, vector<long>(vmax, wmax));


  for(int i = 0; i < N; i++){
    cin >> w[i] >> v[i];
    cerr << "w[i], v[i]" << w[i] << ", " << v[i] << endl;
  }
  for(int i = 0; i< N; i++){
    dp[i][0] = 0;
  }
  for(int j = 0; j< vmax; j++){
    if(j <= v[0]) dp[0][j] = w[0];
  }

  for(int i = 1; i < N; i++){
    for(int j = 0; j < vmax; j++){
      if(j - v[i] >= 0){
        dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i]] + w[i]);
      } 

      if(j <=  v[i]){
        dp[i][j] = min(dp[i][j], w[i]);
      }

      dp[i][j] = min(dp[i][j], dp[i-1][j]);
    }
  }

  // N-1で、vmax以下の最大値で、W以下なものを探す

  long ans = 0;
  for(int i = 0; i < vmax; i++){
    cerr << "dp[N-1]["<<i<<"]: " << dp[N-1][i] << endl;
    if(dp[N-1][i] <= W){
      ans = i;
    }
  }

  cout << ans << endl;

}

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

int main(){
  int n;
  cin>>n;
  int input[n];
  for(int i=0;i<n;i++)cin>>input[i];
  int cnt=0;
  for(int i=0;i<n;i++){
    for(int j=2;j<=sqrt(input[i]);j++){
      if(input[i]%j==0){cnt++;break;}
    }
  }
  cout<<n-cnt<<endl;
}



Measured memory_bytes: 3112
#include <iostream>                                                                                                               
#include <string>                                                                                                                 
using namespace std;                                                                                                              
                                                                                                                                  
int main (void) {                                                                                                                 
  string c;                                                                                                                       
  cin >> c;                                                                                                                       
  if (c[0]=='x' && c[c.size()-1]=='x') {                                                                                          
    cout << "x" << endl;                                                                                                          
  } else {                                                                                                                        
    cout << "o" <<endl;                                                                                                           
  }                                                                                                                               
}                                                                                                                                 
                        

Measured memory_bytes: 3164
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <limits.h>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;



int main() {
    
    long long ans[10] = {0};
    int count = 1;
    
    long long H, W;
    int N;
    
    cin >> H;
    cin >> W;
    cin >> N;
    
    vector< pair<long long, long long> > pairs;
    
    for ( long long i = 0; i < N; i++ ) {
        
        long long a, b;
        
        cin >> a;
        cin >> b;
        
        for ( long long i = 0; i < 3; i++ )
        for ( long long j = 0; j < 3; j++ ) {
            if ( a-i > 0 && a-i <= H-2 && b-j > 0 && b-j <= W-2 ) {
                pairs.push_back( make_pair(a-i, b-j) );
            }
        }
    }
    
    sort( pairs.begin(), pairs.end() );
    
    
    for ( long long i = 1; i < pairs.size(); i++ ) {
        
        if ( pairs[i].first == pairs[i-1].first && pairs[i].second == pairs[i-1].second ) {
            count++;
        }
        else {
            ans[count]++;
            count = 1;
        }
        
    }
    
    if ( N ) { ans[count]++; }
    
    
    int sum = 0;
    for ( int i = 1; i < 10; i++ ) {
        sum += ans[i];
    }
    
    ans[0] = (H-2)*(W-2) - sum;
    
    for ( int i = 0; i < 10; i++ ) {
        cout << ans[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 18536
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int INF=INT_MAX,MOD=1e9+7;

int main(){
    int h,w; cin>>h>>w;
    int n; cin>>n;
    int c[h][w],y=0,x=0;
    bool turn=1;
    for(int q=1;q<=n;q++){
        int a; cin>>a;
        while(a--){
            c[y][x]=q;
            if(turn) x++;
            else x--;
            if(x<0||w-1<x){
                if(turn) x=w-1;
                else x=0;
                y++;
                turn=!turn;
            }
        }
    }
    rep(i,h)
        rep(j,w)
            cout<<c[i][j]<<(j!=w-1?" ":"\n");
    return 0;
}


Measured memory_bytes: 384
a,v= map(int, input().split())
b,w= map(int, input().split())
t= int(input())
if b < 0 :
  if (a - v*t) <= (b-w*t):
  		print("YES")
  else:
  		print("NO")
else:
	if (a + v*t) >= (b+w*t):
  		print("YES")
	else:
  		print("NO")

Measured memory_bytes: 9220
N = int(input())
H_list = list(map(int,input().split()))
Flag = True

if N != 1:
    for i in range(N-1):
        if H_list[N-1-i-1] - H_list[N-1-i] > 1:
            Flag = False
            break
        elif H_list[N-1-i-1] - H_list[N-1-i] == 1:
            H_list[N-1-i-1] = H_list[N-1-i-1] -1
        else:
            continue
    
if Flag == True:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14252
h, w, k = map(int, input().split())
c = [input() for i in range(h)]

ans = 0
for bit_state_h in range(1 << h):
    for bit_state_w in range(1 << w):
        cnt = 0
        for i in range(h):
            for j in range(w):
                if c[i][j] == "#" and (not(bit_state_h & (1 << i))) and (not(bit_state_w & (1 << j))):
                    cnt += 1
        if cnt == k:
            ans += 1
print(ans)


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9+7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

ll gcd(ll x, ll y){ return y==0? x: gcd(y, x%y); }
ll lcm(ll x, ll y){ return (x  / gcd(x, y) * y ); }

int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	string s;
	cin >>s;
	int n=sz(s), one=0, two=0;
	rep(i,n) one += s[i]=='1';
	two = n- one;
	
	cout <<min(one,two) * 2<<"\n";
	return 0;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
const int inf = 2147483647;
const ll linf = 1e18;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

template<class T>
struct seg_tree{
    T N;
    T init = inf;
    vector<T> node;

    seg_tree(int n){
        N = 1;
        while(N < n) N *= 2;
        node.resize(N * 2 - 1);
        for(auto& u : node){
            u = init;
        }
    }

    void update(int i, T x){
        i += N - 1;
        node[i] = x;
        while(i > 0){
            i = (i - 1) / 2;
            node[i] = min(node[i * 2 + 1], node[i * 2 + 2]);
        }
    }

    T get_min(int a, int b, int k = 0, int l = 0, int r = -1){
        if(r == -1) r = N;
        if(b <= l || r <= a) return init;
        if(a <= l && r <= b) return node[k];

        T vl = get_min(a, b, k * 2 + 1, l, (l + r) / 2);
        T vr = get_min(a, b, k * 2 + 2, (l + r) / 2, r);
        return min(vl, vr);
    }
};

int n, q;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> q;
    seg_tree<int> seg(n);
    
    for(int i = 0; i < q; i++){
        int com, x, y;
        cin >> com >> x >> y;
        if(com == 0){
            seg.update(x, y);
        }else{
            cout << seg.get_min(x, y + 1) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3896
#include <iostream>
#include "stdio.h"
using namespace std;

void func(int x);

int main()
{
	int x;
  scanf("%d",&x );
  func(x);
  return 0;
}

void func(int x)
{
  int h,m,s;
  h = x/3600;
  x -= 3600*h;
  m = x/60;
  x -= 60*m;
  s = x;
  std::cout << h << ":" << m << ":" << s << endl;
}



Measured memory_bytes: 3236