akhauriyash/Code-Regression huggingface dataset:
/* ex3_4
    sak_Citrus*/

#include <stdio.h>

int main(void){
    //標準入力
    int num;
    scanf("%d",&num);
    for(int i=1;i<10;i++){
        //nがiで割り切れてなおかつその商が10未満なら
        if(num%i == 0 && num/i < 10){
            printf("Yes\n");
            break;
        }
        //最後までbreakされなかったら九九にはない
        if(i == 9)
            printf("No\n");
    }

    return 0;

}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
const int MAX_N = 51;
int H, W;
char board[MAX_N][MAX_N];
bool visited[MAX_N][MAX_N];
void bfs()
{
    queue<tuple<pii, int>> que; //pos,pre,cost
    que.emplace(mt(mp(1, 1), 0));
    int result = -1;
    while (not que.empty())
    {
        auto p = que.front();
        que.pop();
        pii pos;
        int cost;
        tie(pos, cost) = p;
        int y = pos.first;
        int x = pos.second;
        //goal
        if (y == H and x == W)
        {
            result = cost;
            break;
        }
        //pre visited
        if (visited[y][x])
        {
            continue;
        }
        visited[y][x] = true;
        for (int i = 0; i < 4; i++)
        {
            int ny = y + dy[i];
            int nx = x + dx[i];
            if (board[ny][nx] == '.')
            {
                que.emplace(mt(mp(ny, nx), cost + 1));
            }
        }
    }
    if (result == -1)
    {
        cout << result << endl;
        return;
    }
    
    int white = 0;
    for (int i = 1; i <= H; i++)
    {
        for (int j = 1; j <= W; j++)
        {
            if (i == 1 and j == 1){
                continue;
            }
            if (i == H and j == W){
                continue;
            }
            if (board[i][j] == '.')
            {
                white++;
            }
        }
    }
    // cout << result << " " << white << endl;
    cout << white - result  + 1 << endl;
}

int main()
{
    cin >> H >> W;
    for (int i = 1; i <= H; i++)
    {
        for (int j = 1; j <= W; j++)
        {
            cin >> board[i][j];
        }
    }
    bfs();
    return 0;
}


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

#define FOR(i,a,b) for(size_t i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

typedef pair<ll, ll> pll;
// const ll INF = (ll)1e18;

signed main() {
	int n, m;
	cin >> n >> m;
	int res = (1900 * m + (100 * (n - m))) * pow(2, m);
	cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+1;
vector <vector<int>> cost(3, vector<int>(N, 0));
vector<vector<int>> memo(3, vector<int>(N, 0));

int happy(int start, int pos, int n){
    if (pos==n) return cost[start][n];
    else if (memo[start][pos]) return memo[start][pos];
    else {
        int max_happy = 0;
        for (int i=0; i<3; i++){
            if (i==start) continue;
            max_happy = max(max_happy, cost[start][pos]+happy(i, pos+1, n));
        }
        memo[start][pos] = max_happy;
        return max_happy;
    }
    
}

int main(){
    int n; cin >> n;
    for (int j=1; j<n+1; j++){
        for (int i=0; i<3; i++){
            cin >> cost[i][j];
        }
    }

    cout << max(happy(0, 1, n), max(happy(1, 1, n), happy(2, 1, n))) << endl;

    return 0;
}

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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef LOCAL
#define debug(x...) cerr <<"at line "<< __LINE__<<": [" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;


template<class T> 
using ordered_set= tree<T, null_type, 
		less<T>, 
		rb_tree_tag, tree_order_statistics_node_update> ;

template<class T> 		
using ordered_mset= tree<T, null_type, 
		less_equal<T>, 
		rb_tree_tag, tree_order_statistics_node_update> ;
		
*/
 
/*
 
PBDS
-------------------------------------------------
			0 based indexing
-------------------------------------------------			 
1) insert(value)
2) erase(value)
3) order_of_key(value) // Number of items strictly smaller than value
4) *find_by_order(k) : K-th element in a set (counting from zero)
 
*/
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());	

ll power(ll b)
{
	ll ans=1;
	for(int i=1;i<=5;i++) ans*=b;
	
	return ans;
}

void solve()
{
	ll n;
	cin>>n;
	
	if(n==1)
	{
		cout<<1<<" "<<0;
		return;
	}
	
	vector<ll>fact;
	
	for(ll i=1;i*i<=n;i++)
	{
		if(n%i==0)
		{
			fact.push_back(i);
			if(i*i!=n) fact.push_back(n/i);
		}
	}
	
	sort(fact.begin(),fact.end());
	
	for(auto it: fact)
	{
		for(int i=0;i<10000;i++)
		{
			ll a=i;
			ll b=i-it;
			
			if(power(a)-power(b)==n)
			{
				cout<<a<<" "<<b;
				return;
			}
			
			if(power(b)-power(a)==n)
			{
				cout<<b<<" "<<a;
				return;
			}
		}
	}
	
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	solve();
	
	#ifdef LOCAL
	cerr<<"\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
	#endif
	
	
	return 0;
}


Measured memory_bytes: 3640
use std::io::BufRead;

pub struct StdinReader<R: BufRead> {
    pub buf_reader: R,
    pub buf: String,
}

impl<R: BufRead> StdinReader<R> {
    pub fn new(r: R) -> Self {
        StdinReader {
            buf_reader: r,
            buf: String::with_capacity(10000),
        }
    }
}

#[macro_export]
macro_rules! input {
    ($reader : expr, $t : ty) => { // one variable
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: $t = reader.buf.trim().parse().unwrap();
                reader.buf.clear();
                tmp_var
            },
        }
    };
    ($reader : expr, $t0 : ty, $t1 : ty) => { // 2 tuple
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: Vec<$t0> = reader.buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
                reader.buf.clear();
                (tmp_var[0].clone(), tmp_var[1].clone())
            }
        }
    };
    ($reader : expr, $t0 : ty, $t1 : ty, $t2 : ty) => { // 3 tuple
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: Vec<$t0> = reader.buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
                reader.buf.clear();
                (tmp_var[0].clone(), tmp_var[1].clone(), tmp_var[2].clone())
            }
        }
    };
    ($reader : expr, $t : ty; $size : expr) => { // Vector
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: $t = reader.buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
                reader.buf.clear();
                tmp_var
            }
        }
    };
}

fn main() {
    solve_b();
}
fn solve_b() {
    let handle = std::io::stdin();
    let mut r = StdinReader::new(handle.lock());
    let n: usize = input!(r, usize);
    let s: String = input!(r, String);
    let mut blue = 0;
    let mut red = 0;
    for c in s.chars() {
        if c == 'R' {
            red += 1;
        } else if c == 'B' {
            blue += 1;
        } else {
            panic!("wtf");
        }
    }
    if red > blue {
        println!("Yes");
    } else {
        println!("No");
    }
}



Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

using P = pair<bool, int>;
#define fi first
#define se second

int main() {
    int n, m;
    cin >> n >> m;
    P res[n];
    fill(res, res+n, P{false, 0});
    for (int i=0, p; i<m; i++) {
        string s;
        cin >> p >> s;
        p--;
        if (res[p].fi) continue;
        if (s == "AC") res[p].fi = true;
        else res[p].se++;
    }
    int ac = 0, wa = 0;
    for (auto &r:res) {
        if (!r.fi) continue;
        ac++;
        wa += r.se;
    }
    cout << ac << ' ' << wa << '\n';
    return 0;
}

Measured memory_bytes: 1024
x = int(input())

temp = [0 for _ in range(1001)]
for i in range(1, 32):
    for j in range(2,10):
        hoge = i ** j
        if hoge > 1000:
            break
        else:
            temp[hoge] = 1

for i in range(x, -1, - 1):
    if temp[i] == 1:
        print(i)
        exit()

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

using namespace std;

int n,m,t = 1;
int g[10][10] = {};

int dfs(int node,int run){
    int ans = 0;
    //cout << node << " " << run << endl;

    for(int i = 1; i<= n;i++){
        if(g[node][i] == 1 && ((run & (1<<(i-1))) == 0)){
            ans += dfs(i,run | (1<<(i-1)));
        }
    }

    if(run == t)return ans + 1;
    else return ans;
}
int main(){
    
    cin >> n >> m;

    t = (t << n)-1;
    for(int i = 0;i < m;i++){
         int a,b;
         cin >> a >> b;
         g[a][b] = 1;
         g[b][a] = 1;
    }
    

    cout << dfs(1,0x01) <<endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	char str[1000];
	int i;
	fgets(str,1000,stdin);
	i = 0;
	while(str[i+4] != '\0'){
		if(str[i] == 'a'){
			if(str[i+1] == 'p'){
				if(str[i+2] == 'p'){
					if(str[i+3] == 'l'){
						if(str[i+4] == 'e'){
							str[i] = 'p';
							str[i+1] = 'e';
							str[i+2] = 'a';
							str[i+3] = 'c';
							str[i+4] = 'h';
						}
					}
				}
			}
		}
		else if(str[i] == 'p'){
			if(str[i+1] == 'e'){
				if(str[i+2] == 'a'){
					if(str[i+3] == 'c'){
						if(str[i+4] == 'h'){
							str[i] = 'a';
							str[i+1] = 'p';
							str[i+2] = 'p';
							str[i+3] = 'l';
							str[i+4] = 'e';
						}
					}
				}
			}
		}
		i++;
	}
	printf("%s",str);
	return 0;
}

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

using namespace std;

using ll = long long;

int main(void) {
    ll yen;
    scanf("%lld", &yen);
    ll ans = 1000 * (yen / 500) + 5 * ((yen % 500) / 5);
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 256
import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid_int(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    R, C, K = NMI()
    grid = make_grid_int(R, C, 0)
    for i in range(K):
        r, c, v = NMI()
        grid[r-1][c-1] = v

    dp = [[[0 for _ in range(C+2)] for _ in range(R+2)] for _ in range(4)]

    for r in range(R+1):
        for c in range(C+1):
            for i in range(4):
                now = dp[i][r][c]
                try:
                    val = grid[r][c]
                except:
                    val = 0

                if i == 3:
                    # 取らずに下
                    dp[0][r + 1][c] = max(now, dp[0][r + 1][c])
                    continue

                # 取って下
                dp[0][r+1][c] = max(now + val, dp[0][r+1][c])
                # 取らずに下
                dp[0][r+1][c] = max(now, dp[0][r+1][c])
                # 取って横
                dp[i+1][r][c+1] = max(now + val, dp[i+1][r][c+1])
                # 取らずに横
                dp[i][r][c+1] = max(now, dp[i][r][c+1])

    print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 460764
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
const long long INF = 1LL << 60;

ll n;
int main()
{
    int x;
    cin >> x;
    if (x < 600)
    {
        cout << 8 << endl;
    }
    else if (x < 800)
    {
        cout << 7 << endl;
    }
    else if (x < 1000)
    {
        cout << 6 << endl;
    }
    else if (x < 1200)
    {
        cout << 5 << endl;
    }
    else if (x < 1400)
    {
        cout << 4 << endl;
    }
    else if (x < 1600)
    {
        cout << 3 << endl;
    }
    else if (x < 1800)
    {
        cout << 2 << endl;
    }
    else
    {
        cout << 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3644
S = input()
T = input()
D = []
for i in range(len(S) - len(T) + 1):
    SS = S[i:i+len(T)]
    dif = 0
    for j in range(len(T)):
        if T[j] != SS[j]:
            dif += 1
    D += [dif]
            
print(min(D))


Measured memory_bytes: 9108
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#define fo(i,n) for(long long i=0;i<n;i++)
#define ll long long int
#define inf 999999999999999999
#define pb push_back
#define fi first
#define se second
#define vi vector<ll>
#define vii vector<vector<ll>>
#define pi pair<ll,ll>
#define mp make_pair
#define MOD 1000000007
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define fio ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
//cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
//freopen("explicit.in", "r", stdin);
//freopen("explicit.out", "w", stdout);
 
void SieveOfEratosthenes() 
{ 
    bool prime[10000001];
    memset(prime, true, sizeof(prime)); 
  
    for (ll p=2; p*p<=10000000; p++) 
    { 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (ll i=p*p; i<=10000000; i += p) {
                prime[i] = false; 
            }
        } 
    }  
} 
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a);
        a = (a * a);
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
	if(b%a==0)
	   return a;
	return gcd(b%a,a);
}
ll nCrModpDP(ll n, ll r, ll p) 
{ 
    ll C[r+1]; 
    memset(C, 0, sizeof(C));   
    C[0] = 1;
    for (ll i = 1; i <= n; i++) 
    {
        for (ll j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
} 
ll nCrModp(ll n, ll r, ll p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
   ll ni = n%p, ri = r%p; 
  
   return (nCrModp(n/p, r/p, p) * 
           nCrModpDP(ni, ri, p)) % p; 
} 
int32_t main() 
{
    fio
	ll j,i,n,t,l,r,c,h,k,m,maxi,d,x;
	cin>>n;
	c=0;
	m=0;
	for(j=0;j<n;j++)
	{
		cin>>x;
		m=max(m,x);
		c=c+m-x;
	}
	cout<<c;
}


	

		

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

int main() {
  int a, b, c, x, y, sum;

  cin >> a >> b >> c >> x >> y;

  if (a + b > c * 2) {
    if (x < y) {
      sum = c * x * 2;
      for (int i = 0; i < y - x; i++) {
        if (b > c * 2) {
          sum += c * 2;
        } else {
          sum += b;
        }
      }
    } else {
      sum = c * y * 2;
      for (int i = 0; i < x - y; i++) {
        if (a > c * 2) {
          sum += c * 2;
        } else {
          sum += a;
        }
      }
    }
  } else {
    sum = a * x + b * y;
  }

  cout << sum << endl;
}


Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        Array.Sort(a);
        var res = 0;
        for (int i = 0; i < 2 * n; i += 2)
            res += a[i];
        Console.WriteLine(res);
    }
}


Measured memory_bytes: 11220
let cnt = ref 0
let (g : int list ref) = ref []
let n_g = ref 0

let insertion_sort (a : int array) n g =
  for i = g to n - 1 do
    let v = a.(i) in
    let j = ref (i - g) in
    while !j >= 0 && a.(!j) > v do
      a.(!j+g) <- a.(!j);
      j := !j - g;
      incr cnt;
    done;
    a.(!j+g) <- v;
  done

let generate_g n =
  let new_g = ref 1 in
  incr n_g;
  while !new_g <= n do
    g := !new_g :: !g;
    new_g := int_of_float (4.**(float_of_int !n_g) +. 3.*.2.**(float_of_int (!n_g - 1)) +. 1.);
    incr n_g;
  done;
  decr n_g

let shell_sort (a : int array) n =
  cnt := 0;
  generate_g n;
  List.iter (fun g -> insertion_sort a n g) !g

let () =
  let n = read_int () in
  let a = Array.init n (fun _ -> read_int ()) in
  shell_sort a n;
  Printf.printf "%d\n" !n_g;
  List.iteri (fun i n -> if i <> 0 then print_string " "; print_int n) !g;
  print_newline ();
  Printf.printf "%d\n" !cnt;
  Array.iter (fun n -> Printf.printf "%d\n" n) a

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
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(a>b){a=b;return 1;}return 0;}
#if loc||local
template<class T>void dump(T&& t){cerr<<t<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  ll n,k;
  cin>>n>>k;
  vector<ll> v(n);
  cin>>v;
  auto vl = v,vr = v;
  reverse(begin(vr),end(vr));

  ll ans = 0;
  for(int l=0;l<=n;++l)for(int r=0;r<=n;++r){
    if(l+r>n)break;
    if(l+r>k)break;
    priority_queue<ll,vector<ll>,greater<>> que;
    for(int i=0;i<l;++i)que.emplace(vl[i]);
    for(int i=0;i<r;++i)que.emplace(vr[i]);
    int s = k-(l+r);
    while(s--){
      if(que.empty())break;
      if(que.top()<0)que.pop();
      else break;
    }
    ll sum = 0;
    while(!que.empty()){
      sum += que.top();
      que.pop();
    }
    chmax(ans,sum);
  }
  cout<<(ans)<<endl;

}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
const int maxn=105;
const int maxw=10e5+5;
long long dp[maxn][maxw];
int main()
{
    int n,w;
    cin>>n>>w;
    vector<int>weight(n),val(n);
    for(int i=0;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        weight[i]=x;
        val[i]=y;
    }

    for(int i=0;i<=n;i++)
        for(int j=0;j<=w;j++)
    {
        if(i==0||j==0)
            dp[i][j]=0;
        else if(weight[i-1]>j)
        dp[i][j]=dp[i-1][j];
        else
            dp[i][j]=max(dp[i-1][j],dp[i-1][j-weight[i-1]]+val[i-1]);

    }
    cout<<dp[n][w]<<endl;
    return 0;
}


Measured memory_bytes: 287744
import sys
input = sys.stdin.readline
N, W = map(int, input().split())
dp = [0] * (W + 1)
def dp_opt(n, w):
    for _ in range(N):
        w, v = map(int, input().split())
        for j in range(W, w-1, -1):
            tmp = dp[j-w] + v
            if tmp > dp[j]:
                dp[j] = tmp
    print(dp[-1])
dp_opt(N,W)

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

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

  int len = S.size();
  
  int counter = len / 2;
  
  int ans = 0;
  
  rep(i, counter) {
    if (S[i] == S[len - 1]) {
    }
    else {
      S[len - 1] = S[i];
      ans ++;
    }
    len --;
  }
  
  cout << ans << endl;

}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include <stdbool.h>
int main() {
	char a[200][200];
	char b[200][200];
	char c[200][200];
	bool check = false;
	int H, W, i, j, y, t;
	//入力
	scanf("%d %d", &H, &W);
	for (i = 0; i < H; i++) {
		for (j = 0; j <= W; j++) {
			scanf("%c", &a[i][j]);
		}
	}

	//
	y = 0;
	for (i = 0; i < H; i++) {
		check = false;
		for (j = 0; j <= W; j++) {
			if (a[i][j] == '#') {
				check = true;
			}
		}
		if (check) {
			for (j = 0; j <= W; j++) {
				b[y][j] = a[i][j];
			}
			y++;
		}
	}

	t = 0;
	for (i = 0; i <= W; i++) {
		check = false;
		for (j = 0; j < y; j++) {
			if (b[j][i] == '#') {
				check = true;
			}
		}
		if (check) {
			for (j = 0; j < y; j++) {
				c[j][t] = b[j][i];
			}
			t++;
		}
	}



	for (i = 0; i < y; i++) {
		c[i][t] = '\n';
	}

	for (i = 0; i < y; i++) {
		for (j = 0; j <= t; j++) {
			printf("%c", c[i][j]);
		}
	}

	return 0;
}


Measured memory_bytes: 256
N=int(input())
X=[int(s) for s in input().split(" ")]

X.sort()

Ans=N*(X[-1]**2)
for i in range(X[-1]+1):
    Sum=0
    for j in range(N):
        Sum=Sum+(X[j]-i)**2
    if Sum<Ans:
        Ans=Sum

print(Ans)

Measured memory_bytes: 3064
/*我是萌新*/
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <iomanip> 
typedef long long LL;
const int mod = 1000000009;
using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    LL n;
    while (cin >> n)
    {
        LL* p = new LL[n + 5],ans=0;
        for (int i = 1; i <= n; i++)
            cin >> p[i];
        sort(p+1, p + n+1);
        ans = p[(n/2)+1] - p[n/2];
        cout << ans << '\n';
    }
}



Measured memory_bytes: 1024
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
#include <map>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
int main() {
    int n;
    cin >> n;
    long long ans = 1;
    long long MX = 1e18;
    bool ng = false;
    rep(i, 0, n){
        long long a;
        cin >> a;
        if(a==0){
            cout << 0 << endl;
            return 0;
        }
        if(ng || MX/ans < a){
            ng = true;
        }
        ans *= a;
    }
    if (ng){
      cout << -1 << endl;
    } else {
      cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define FOR(a,b,c) for(int a = (b); a <= (c); a++)
#define RFOR(a,b,c) for(int a = (b); a >= (c); a--)
#define all(x) (x).begin(), (x).end()
#define vi vector <int>
#define vvi vector <vi>
#define ll long long
#define vll vector <ll>
#define vvl vector <vll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ep emplace
#define fs first
#define sd second
#define mod 998244353
#define EPS 1e-9
#define tc int t; cin >> t; while(t--)
using namespace std;

int main() {
	FIO;
	ll x; cin >> x;
	ll a = 100;
	FOR(i,0,10000) {
		if (x <= a) return cout << i << '\n', 0;
		a += (a / 100);
	}
	return 0;
}

Measured memory_bytes: 3652
# unihernandez22
# https://atcoder.jp/contests/abc128/tasks/abc128_b
# implementation

n = int(input())
restaurants = []

for i in range(1, n+1):
    name, score = input().split()
    restaurants.append((name, -int(score), i))

restaurants.sort()
for i in restaurants:
    print(i[2])


Measured memory_bytes: 9068
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define testcase ll tt; cin>>tt; while(tt--)
#define pb push_back
#define nn cout<<"\n"
#define MOD 1000000007
#define vll vector<ll>
#define here cout<<"I'm here\n";
template<class T> void dispvector(vector<T> v){for(int i=0;i<v.size();i++) cout<<v[i]<<" "; nn;}
void vout(vector<ll> ans){
    for(auto ele:ans) cout<<ele;
}
ll gcd(ll a,ll b){
    if(a==0)
        return b;
    else
        return gcd(b%a,a);
}
ll findGCD(vector<ll> arr,ll n) 
{ 
    ll result = arr[0]; 
    for (ll i = 1; i < n; i++) 
        result = gcd(arr[i], result);
    return result; 
}
int main() {
    SPEED;
    cout.precision(8);
    cout << fixed;
    ll n,m;
    cin>>n>>m;
    cout<<(n*(n-1)/2)+(m*(m-1)/2);
    return 0;
}

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

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

    int min;
    if (a * n < b)
    {
        min = a * n;
    }
    else
    {
        min = b;
    }

    cout << min << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T>
bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ld,ll>;
//--GLOBAL---------------------------------
ld EPS=0;
struct edge{ll to; ld cost;}; //edgeパラメータ
struct graph{
  ll N; //ノードの個数
  vector<vector<edge> > G; //G[辺の元]((.to辺の先,.costコスト),...)
  vector<ld> d; // dist[n] = ノードnまでのの重み
  vector<ll> parent;

  graph(ll n): N(n), G(N), d(n,INF2), parent(N) {}

  void add_edge(ll s, ll t, ld cost){
    G[s].emplace_back((edge){t, cost});
    G[t].emplace_back((edge){s, cost}); //無向ならON
  }

  void dijkstra(ll s){
    d[s] = (ld)0;
    priority_queue<P,vector<P>, greater<P> > que; //ansが小さい順に出る
    que.push(P((ld)0,s)); // P < ans , Node >
    while(!que.empty()){
      P p = que.top(); que.pop(); //pに <ans,Node> 入れる
      ll v = p.second; //vに Node 入れる
      if(d[v] < p.first) continue; //すでに良い数値が入っているならパス
      rep(i,G[v].size()){
        edge& E = G[v][i];
        if(d[E.to] > d[v] + E.cost){ //更新するなら
          d[E.to] = d[v]+ E.cost;
          parent[E.to] = v; //親を記録,goalから遡れば道順
          que.push(P(d[E.to], E.to));
        }
      }
    }
  }
};
//--MAIN-----------------------------------
void Main() {
    ll xs,ys,xg,yg; cin>>xs>>ys>>xg>>yg;
    ll N; cin>>N;
    graph g(N+2);
    vector<ll> x(N+2);
    vector<ll> y(N+2);
    vector<ld> r(N+2);
    x[0]=xs;
    y[0]=ys;
    r[0]=0;
    x[N+1]=xg;
    y[N+1]=yg;
    r[N+1]=0;
    reps(i,1,N+1){
        cin>>x[i]>>y[i]>>r[i];
    }
    rep(i,N+1){
        reps(j,i+1,N+2){
            ld kyori=sqrt((ld)((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])));
            kyori=kyori-r[i]-r[j];
            g.add_edge(i,j,max((ld)0,kyori));
        }
    }
    g.dijkstra(0);
    cout<< g.d[N+1] <<"\n";

}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 42348
a,b = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
s = 0 
k = 0
for i,t in enumerate(reversed(x)):
    s+= (a-i-1)*t
    s-= i*t
for i,t in enumerate(reversed(y)):
    k+= (b-i-1)*t
    k-= i*t
print((s*k)%(10**9+7))


Measured memory_bytes: 18624
#include<bits/stdc++.h>
using namespace std;
int coin[2]={4,7};
int dp[2][101];
bool coin_change(int i,int value)
{
    if(i>=2) {
        return value==0;
    }
    if(dp[i][value]!=-1) return dp[i][value];
    int ret1=0,ret2=0;
    if(value-coin[i]>=0) ret1=coin_change(i,value-coin[i]);
    ret2=coin_change(i+1,value);
    return dp[i][value]=ret1|ret2;
}
main()
{
    memset(dp,-1,sizeof(dp));
    int n;
    while(~scanf("%d",&n))
    {
        coin_change(0,n) ? puts("Yes") : puts("No");
    }
    return 0;
}

Measured memory_bytes: 256
n, x = map(int, input().split())
l = list(map(int, input().split()))
d = [0]
for i in range(1,n+1):
    d.append(d[i-1]+l[i-1])
counter = 0
for i in range(x+1):
    if i in d:
        counter += 1
    else:
        continue
print(counter)

Measured memory_bytes: 3060
S = input()
N = len(S)
sub1 = S[:(N - 1) // 2]
sub2 = S[(N + 3) // 2 - 1:]
if S == S[::-1] and sub1 == sub1[::-1] and sub2 == sub2[::-1]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main( void )
{
  int n,s;
  while( 1 ){
    int ret = 0;
    cin>>n>>s;
    if( n==0 && s==0 ) break;
    for( int i=0; i < (1<<10); i++ ){
      int a=1,b=0,c=0;
      for( int j=0; j<10; j++ ){
        if( i & a ){ b += j; c++; }
        a <<= 1;
      }
      if( c == n && b == s ) ret++;
    }
    cout << ret << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define Speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;

#define st              first
#define nd              second
#define pb              push_back
#define pf              push_front
#define all(a)          (a).begin(), (a).end()
#define lwb             lower_bound
#define upb             upper_bound
#define vvll            vector<vector<ll> >
#define Mset(s, n)      memset(s, n, sizeof(s))
#define Sz(a)           int((a).size())
#define Max(a, b, c)    max(max((ll)(a), (ll)(b)), (ll)(c))
#define Min(a, b, c)    min(min((ll)(a), (ll)(b)), (ll)(c))
#define Unique(a)       sort(all(a)); (a).resize(unique(all(a)) - (a).begin())

typedef long double ld;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

const ll MOD = 1e9 + 7;
const int oo = 2e9;
const ld PI = acos((ld) -1);
int Getbit(ll x, int k){return (x >> (k - 1)) & 1;}
ll Lcm(ll a, ll b) {return a / __gcd(a, b) * b;}
bool isPrime(ll n){for(ll i = 2; i * i <= n; i++){if(n % i == 0) return 0;} return (n > 1) ? 1 : 0;}
ll Powmod(ll n, ll k, ll p = MOD) {ll r = 1; for(; k; k /= 2, n = n * n % p){if(k & 1) r = r * n % p;} return r;}

const int N = 2e5 + 5;

ll n, m, k;
int a[N];

void Solve(){
    string s, t, u;
    cin >> s >> t;
    cin >> n >> m;
    cin >> u;
    if(s == u) n--;
    if(t == u) m--;
    cout << n << " " << m;
}


int main(){
    Speed;
    cout << fixed << setprecision(10);
    int query = 1;
//    cin >> query;
    while(query--) Solve();
}


Measured memory_bytes: 256
require 'prime'

def calcComb(a, b)
  return calcCombF(a, a - b) if a - b < b

  mul = 1
  div = 1
  i = 0
  while i < b
    mul *= a - i
    div *= i + 1
    i += 1
  end
  mul / div
end

mod = 10**9 + 7
n, m = gets.split.map(&:to_i)
pr = m.prime_division
ans = 1
pr.each { |v| ans *= calcComb(n - 1 + v[1], v[1]) % mod } if n != 1
puts ans % mod


Measured memory_bytes: 3964
#include <iostream>
using namespace std;
int main(void){
    long long n,a,b;
    cin>>n>>a>>b;
    long long ans;
    long long c=n%(a+b);
    if(c>=a){
        ans=n/(a+b)*a+a;
    }
    else{
        ans=n/(a+b)*a+c;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define COUT(x) cout<<(x)<<endl
typedef long long ll;
template<class T> inline void chmax(T& a, T b) {
  if (a < b) a = b;
}

template<class T> inline void chmin(T& a, T b) {
  if (a > b) a = b;
}
const int MOD = 1000000007;
const long long INF = 1LL << 60;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  string S,T;
  cin >> S >> T;
  
  for (int i = 0; i < (int)S.size(); ++i) {
    if (S[i] != T[i]) {
      COUT("No");
      return 0;
    }
  }
  COUT("Yes");
  
}

Measured memory_bytes: 3652
maxn=10**5+10
n=int(input())
b=[0]*maxn
c=[0]*maxn
a=input().split()

for i in range(0,n):
    a[i]=int(a[i])
    if i%2==0:
        b[a[i]]+=1
    else:
        c[a[i]]+=1

max1=max(b)
maxp=b.index(max1)
del b[maxp]
max2=max(b)

ans=0
for i in range(0,maxn):
    ans=max(ans,c[i]+(max2 if i==maxp else max1))

print(n-ans)


Measured memory_bytes: 12472
#include <stdio.h>
int main(void){
    // Your code here!
    int N,Y;
    scanf("%d%d",&N,&Y);
    int num=Y/1000;
    for(int i=0;i<num;i++){
        for(int j=0;j<num;j++){
            if(N-i-j<0) continue;
            if(10000*i+5000*j+1000*(N-i-j)==Y){
                printf("%d %d %d",i,j,(N-i-j));
                return 0;
            }
        }
    }
    printf("-1 -1 -1");
    return 0;
}

Measured memory_bytes: 1736
n = int(input())
ans = 1
pr = []
if n == 2:
  print(1)
  exit()
if n == 3:
  print(2)
  exit()
for i in range(1,int(n**0.5)):
  if (n-1)%i == 0:
    pr.append((n-1)//i)
ans += len(pr)
for i in range(2,int(n**0.5+2)):
  t = n
  while t > i:
    if t%i:
      t %= i
    else:
      t //= i
  if t == 1 or t == i:
    ans += 1
if int(n**0.5+0.5)**2 == n:
  ans -= 1
print(ans)

Measured memory_bytes: 41068
#include <iostream>

using namespace std;

int main(){
  cin.tie(0); 
  ios::sync_with_stdio(false);
  
  string S,T;
  int cnt,bcnt;
  cnt = 0;
  bcnt = 1000;
  cin >> S >> T;

  int tmp = S.size() - T.size() + 1;
  
  for(int i=0;i<tmp;i++){
    cnt = 0;
    for(int j=0;T[j]!='\0';j++){
      if(S[i+j] != T[j]){
        cnt++;
      }
    }
    if( bcnt > cnt ){
    	bcnt = cnt;
    }
  }
  cout << bcnt << endl;
  
  return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <cstdlib>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int triple_max(int x, int y, int z){
    int ans = x;
    if (y > x && y > z) ans = y;
    else if (z > x && z > y) ans = z;

    return ans;
}

int main(){
    string n;
    cin >> n;
    if (n.at(0) == n.at(1) && n.at(1) == n.at(2)) cout << "Yes" << endl;
    else if (n.at(1) == n.at(2) && n.at(2) == n.at(3)) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
signed main()
{
int x=0,y=0,z=0,w=0,n=0,m=0,a=0,b=0;
std::cin >> x>>y;
std::vector<int> v(x);
rep(i,x)std::cin >> v[i];
sort(rall(v));
rep(i,y){
  z+=v[i];
}
std::cout << z << '\n';
return 0;
}


Measured memory_bytes: 256
a, b = map(int, input().split())
ans = 0
for i in range(a, b + 1):
    num = str(i)
    n = len(num)
    for j in range(n // 2):
        if num[j] != num[n - 1 - j]:
            break
        elif j == n // 2 - 1:
            ans += 1
print(ans)

Measured memory_bytes: 3060
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<int,ll> p;

int n;
vector< vector<pair<int,ll> > > cn;
vector<bool> visited;
vector<bool> is_even;

void dfs(int node, bool isodd){
  is_even[node] = isodd;
  visited[node] = true;
  for(p edge : cn[node]){
    if(visited[edge.first]) continue;
    dfs(edge.first, (isodd+edge.second)%2);
  }
}

int main(){
  cin >> n;
  cn.resize(n);
  REP(i,n-1){
    int u,v; ll w;
    cin >> u >> v >> w;
    cn[u-1].push_back(p(v-1,w));
    cn[v-1].push_back(p(u-1,w));
  }
  visited.resize(n);
  fill(visited.begin(),visited.end(),false);
  is_even.resize(n);
  dfs(0,false);
  REP(i,n){
    cout << (is_even[i] ? 0 : 1 )<< endl;
  }
  return 0;
}


Measured memory_bytes: 8576
#include <stdio.h>
#include <string.h>
#include <vector>

int main()
{
	int N, M;
	scanf("%d%d", &N, &M);
	static std::vector<int> edge[100000];
	for (int i = 0; i < M; i++) {
		int A, B;
		scanf("%d%d", &A, &B);
		A--;
		B--;
		edge[A].push_back(B);
		edge[B].push_back(A);
	}

	static int ans[100000] = {0};
	std::vector<int> state;
	for (int v : edge[0]) {
		state.push_back(v);
		ans[v] = 1;
	}
	while (!state.empty()) {
		std::vector<int> next;
		for (int v : state) {
			for (int c : edge[v]) {
				if (ans[c] != 0) continue;
				next.push_back(c);
				ans[c] = v + 1;
			}
		}
		state.swap(next);
	}
	puts("Yes");
	for (int i = 1; i < N; i++) {
		printf("%d\n", ans[i]);
	}

	return 0;
}


Measured memory_bytes: 10124
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

a,b,c,d,e,f = inm()
s = [False]*3001
for i in range(3001):
    for j in range(1501):
        k = c*i+d*j
        if k<=f:
            s[k] = True
w = [False]*32
for i in range(31):
    for j in range(16):
        k = a*i+b*j
        if 100*k<=f:
            w[k] = True
mx = 0.0
mxs = 0
mxsw = 100*a
for t in range(f-99):  # sugar gram
    if not s[t]:
        continue
    ww = t/e  # ww = ax+by must be this much
    for z in range(f//100 + 1, 0,-1):  # water/100
        if not w[z] or z*100+t>f:
            continue
        if z<ww:
            break
        r = t/(100*z+t)
        if r>mx:
            mx = r
            mxs = t
            mxsw = t+100*z
print("{} {}".format(mxsw,mxs))


Measured memory_bytes: 41820
import * as fs from 'fs';

function Picker(input) {
  var lines = input.split('\n');
  var fields = lines.reduce(function(all, line) { return all.concat(line.split(' ')); }, []);
  var p = 0;

  return {
    int: function() {
      return parseInt(fields[p++], 10);
    },
    float: function() {
      return parseFloat(fields[p++]);
    },
    str: function() {
      return fields[p++];
    }
  };
}

const input = fs.readFileSync("/dev/stdin", "utf8");
const pick = Picker(input);

//////////////////////////////////////////

const n = pick.int();
const a = new Array(n).fill(0).map(() => pick.int());

let neg = 0;
let sum = 0;
let min = Infinity;
for (let i = 0; i < n; ++i) {
  if (a[i] < 0) {
    neg++;
  }
  sum += Math.abs(a[i]);
  min = Math.abs(a[i]) < min ? Math.abs(a[i]) : min;
}

if (neg % 2 === 1) {
  sum -= min * 2;
}

/*
const negatives = a.filter(e => e < 0).length;

let sum;
sum = a.map(e => e > 0 ? e : -e).reduce((a, b) => a + b);

if (negatives % 2) {
  const min = a.map(e => e > 0 ? e : -e).sort((a, b) => b - a).pop();
  sum -= min * 2;
}
*/

console.log(sum);

Measured memory_bytes: 29020
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF INT32_MAX / 2
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
#define int long long

signed main() {
    int n, k;
    cin >> n >> k;
    int ans = 0;
    ans += (n / k) * (n / k) * (n / k);
    if (k % 2 == 0) {
        int kp2 = 0;
        rep(i, n) {
            if ((i + 1) % k == k / 2)
                kp2++;
        }
        ans += kp2 * kp2 * kp2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
import sys
input = sys.stdin.readline

class UnionFind:
    N = 0
    cost = 0
    par = []
    
    def init(N):
        UnionFind.N = N
        UnionFind.par = [i for i in range(N)]

    def find(v):
        c = 0
        u = v
        while v != UnionFind.par[v]:
            v = UnionFind.par[v]
            c += 1

        if c > 10:
            while u != v: u, UnionFind.par[u] = UnionFind.par[u], v

        return v

    def union(v, u, c=0):
        vr = UnionFind.find(v)
        ur = UnionFind.find(u)

        if vr == ur: return True

        UnionFind.par[ur] = vr
        UnionFind.cost += c

        return False
            
    def get_cost():
        return UnionFind.cost

    def same(v, u):
        return UnionFind.find(v) == UnionFind.find(u)

def main():    
    n, q = list(map(int, input().split()))
    UnionFind.init(n)

    for i in range(q):
        com, x, y = list(map(int, input().split()))

        if com == 0: UnionFind.union(x, y)
        else: 
            if UnionFind.same(x, y): print(1)
            else: print(0)

if __name__ == '__main__':
    main()


Measured memory_bytes: 6684
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

ll a[501][501];
int main() {
	ll n,m,q;
	cin>>n>>m>>q;
	for(int i=0;i<m;i++){
		ll x,z;
		cin>>x>>z;
		x--;z--;
		a[x][z]++;
	}
	for(int i=0;i<n;i++){
		for(int j=i;j<n-1;j++){
			a[i][j+1]=a[i][j+1]+a[i][j];
		}
	}
	for(int i=0;i<q;i++){
		ll x,z,ans=0;
		cin>>x>>z;
		x--;z--;
		for(int j=x;j<n;j++){
			ans+=a[j][z];
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 2816
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */
public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n=in.nextInt();
            int[][] arr=new int[n][3];
            int[][] dp=new int[n][3];
            for(int i=0;i<n;i++){
                arr[i][0]=in.nextInt();
                arr[i][1]=in.nextInt();
                arr[i][2]=in.nextInt();
            }
            dp[0]=arr[0].clone();
            for(int i=1;i<n;i++){
                for(int j=0;j<3;j++){
                    for(int k=0;k<3;k++){
                        if(k!=j){
                            dp[i][j]=Math.max(arr[i][j]+dp[i-1][k],dp[i][j]);
                        }
                    }
                }
            }
            int[] lastRow=dp[n-1].clone();
            Arrays.sort(lastRow);
            out.println(lastRow[2]);
        }
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

Measured memory_bytes: 52040
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<set>
#include<string>
#include<bitset>
using namespace std;


int main() {
	long long N, K;
	cin >> N >> K;
	long long ans = N % K;
	ans = min(ans, K - ans);
	cout << ans << endl;
	return 0;
}

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

int main(){
  int N;
  cin>>N;
  vector<vector<int>> G(N);
  vector<pair<int,int>> vp;
  for(int i=1;i<N;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
    vp.emplace_back(a,b);
  }

  int K=0;
  map<pair<int,int>,int> I;
  vector<int> cs(N,0); // color of edge between its parent

  vector<int> used(N,0);
  queue<int> que;
  used[0]=1;
  que.emplace(0);
  while(!que.empty()){
    int v=que.front();que.pop();
    if(K<(int)G[v].size()) K=G[v].size();
    int cur=1;
    for(int u:G[v]){
      if(used[u]) continue;
      if(cur==cs[v]) cur++;
      cs[u]=I[make_pair(u,v)]=I[make_pair(v,u)]=cur++;
      used[u]=1;
      que.emplace(u);
    }
  }

  cout<<K<<endl;
  for(auto p:vp) cout<<I[p]<<endl;
  return 0;
}


Measured memory_bytes: 22752
N = int(input())
A = list(input())
B = list(input())
C = list(input())

co = 0
for i in range(N):
	if A[i] != B[i] and B[i] != C[i] and C[i] != A[i]:
		co += 2
	elif A[i] == B[i] and B[i] == C[i]:
		pass
	else:
		co += 1

print(co)

Measured memory_bytes: 3064
#include<iostream>
// #include<vector>

using namespace std;

int make_num(int a, int b, int c){
  int x;
  x = 10000*a + 1000*b + 100*c + 10*b + a;
  return x;
}

int main(){
  int A, B, i, j, k, n=0;
  int num[100000];
  cin >> A >> B;
  for(i=1;i<10;i++) for(j=0;j<10;j++) for(k=0;k<10;k++){
    num[n++] = make_num(i, j, k);
  }
  int ans = 0;
  for(i=0;i<n;i++){
    if(num[i]>=A && num[i]<=B) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256