akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define F first
#define S second
#define ll long long
#define N 3010
using namespace std;
int n;
double dp[N][N],p[N],ans=0;
double pro(int x,int a)
{
	if(x<0)
	{
		return 0;
	}
	if(a<0)
	{
		return 0;
	}
	if(x==0)
	{
		if(a==0)
		{
			return 1-p[x];
		}
		else if(a==1)
		{
			return p[x];
		}
		else
		{
			return 0;
		}
	}
	if(dp[x][a]!=-1)
	{
		return dp[x][a];
	}
	return dp[x][a]=pro(x-1,a)*(1-p[x])+pro(x-1,a-1)*p[x];
}
int main(){
	int i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%lf",&p[i]);
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<=n;j++)
		{
			dp[i][j]=-1;
		}
	}
	for(i=n/2+1;i<=n;i++)
	{
		ans+=pro(n-1,i);
	}
	printf("%.12f\n",ans);
	return 0;
}

Measured memory_bytes: 71040
#include<stdio.h>

typedef struct{
  int a;
  int m;
  int N[100];
  int dis;
  int fin;
  int count;
} Graph;

int way = 1;
Graph G[101];

void DepthFirstSearch(int x){
  int i;

  if(G[x].count == 0){
    G[x].count++;
    G[x].dis = way;
    way++;
  }

  for(i = 0; i < G[x].m; i++){
    if(G[G[x].N[i]].count == 0) DepthFirstSearch(G[x].N[i]);
  }

  if(G[x].fin == 0){
    G[x].fin = way;
    way++;
  }
}

int main(){
  int n, m, i, j;

  scanf("%d", &n);

  for(i = 1; i <= n; i++){
    scanf("%d%d", &G[i].a, &G[i].m);
    G[i].count = G[i].dis = G[i].fin = 0;

    for(j = 0; j < G[i].m; j++) scanf("%d", &G[i].N[j]);
  }

  for(i = 1; i <= n; i++) DepthFirstSearch(G[i].a);

  for(i = 1; i <= n; i++) printf("%d %d %d\n", G[i].a, G[i].dis, G[i].fin);

  return 0;
}

Measured memory_bytes: 636
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<sstream>
using namespace std;

typedef long long ll;

int main() {
  int a[5]; int k;
  for ( int i = 0; i < 5; i++ ) {
    cin >> a[i];
  }
  cin >> k;
  for ( int i = 0; i < 5; i++ ) {
    for ( int j = i+1; j < 5; j++ ) {
      if ( abs(a[i]-a[j]) > k ) {
	cout << ":(" << endl;
	return 0;
      }
    }
  }
  cout << "Yay!" << endl;

  return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()

	A := sc.NextIntArray()

	P := make([]int, 3)
	for i := 0; i < N; i++ {
		if A[i]%4 == 0 {
			P[2]++
		} else if A[i]%2 == 0 {
			P[1]++
		} else {
			P[0]++
		}
	}
	prev := 2
	for i := 0; i < N; i++ {
		hit := false
		for j := 0; j <= 2; j++ {
			if P[j] > 0 && prev+j >= 2 {
				hit = true
				prev = j
				P[j]--
				break
			}
		}
		if !hit {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 7168
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin>>N;
	vector<int> vec(N);
for (int i = 0; i < N; i++) {
  cin >> vec.at(i);
}
sort(vec.begin(), vec.end());
cout<<vec.at(N-1)-vec.at(0)<<endl;
	return 0;
}

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 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()
    }
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item = U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}
fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let mut ans = 0;
    for n in 1..N+1 {
        if n % 2 == 0 {
            continue;
        }
        let mut d = 0;
        for j in 1..n+1 {
            if n % j == 0 {
                d += 1;
            }
        }
        if d == 8 {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    cin >> n;

    vector<string> s(n);
    vl t(n);
    rep(i, n) {
        cin >> s[i] >> t[i];
    }

    string x;
    cin >> x;

    ll ans = 0;
    bool ok = false;
    rep(i, n) {
        if(ok) {
            ans += t[i];
        }
        else {
            if(s[i] == x) {
                ok = true;
            }
        }
    }

    out(ans);
    re0;
}

Measured memory_bytes: 256
n=int(input())
l=[0]*10**7
s=int(n**0.65)+1
for x in range(1,s):
    for y in range(1,s-x):
        for z in range(1,s-x-y):
            l[x*x+y*y+z*z+x*y+y*z+z*x-1]+=1
for i in range(n):
    print(l[i])


Measured memory_bytes: 147488
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
#include <iomanip>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;


int main(){
    int k,a,b;
    cin >> k >> a >> b;
    for(int i = a; i <= b; i++){
        if(i%k == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3636
/* Be strong, be fearless, be beautiful :D
And believe that anything is possible :))
when you have the right people there
to support you :) */
//RTn_E
#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;
#define _Sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define _file freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define ll long long
#define ld long double
#define sp setprecision
#define pb push_back
#define F first
#define S second
#define mk make_pair
#define pii pair < int , int >
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod = 1e9 + 7;
const int maxn = 1e6 + 100;
const ll inf = 1e18;

//Main CODE :/\

vector < int > g , g4 , g2 , g3;
int main() {
    _Sync
    int n;
    cin >> n;
    if (n == 3)
        return cout << "2 5 63\n" , 0;
    if (n == 4)
        return cout << "2 5 63 20\n" , 0;
    if (n == 6)
        return cout << "2 3 6 9 12 4\n" , 0;
    for (int i = 4; i <= 3e4; i++){
        if (i % 6 == 0)
            g.pb(i);
        if (i % 6 == 2)
            g2.pb(i);
        if (i % 6 == 3)
            g3.pb(i);
        if (i % 6 == 4)
            g4.pb(i);
    }
    for (int i = 2e4 - n; i ; i--){
        if (i == 1)
            g.pop_back();
        else if (g2.size())
            g2.pop_back() , g4.pop_back() , i--;
        else if (g3.size() > 1)
            g3.pop_back() , g3.pop_back() , i--;
        else
            g.pop_back();
    }
    cout << 2 << " " << 3 << " ";
    for (auto u : g)
        cout << u << " ";
    for (auto u : g2)
        cout << u << " ";
    for (auto u : g3)
        cout << u << " ";
    for (auto u : g4)
        cout << u << " ";
    cout << "\n";
    return 0;
}
//The_End
//Game Over :D


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

int main() {
 vector<vector<int>> data(3, vector<int>(3));
    for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> data.at(i).at(j);
    }
  }
  
    int a1, a2, a3, b1, b2, b3, c11, c12, c13, c21, c22, c23, c31, c32, c33;
  c11 = data.at(0).at(0);
  c12 = data.at(0).at(1);
  c13 = data.at(0).at(2);
  c21 = data.at(1).at(0);
  c22 = data.at(1).at(1);
  c23 = data.at(1).at(2);
  c31 = data.at(2).at(0);
  c32 = data.at(2).at(1);
  c33 = data.at(2).at(2);
  
 a1 = 0;
  b1 = c11 - a1;
  b2 = c12 - a1;
  b3 = c13 - a1;
  a2 = c21 - b1;
  a3 = c31 - b1;
  
  if(a2 + b2 == c22 && a2 + b3 == c23 && a3 + b2 == c32 && a3 + b3 == c33) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}
    

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a,b;
	scanf("%d" "%d" ,&a,&b);

	if(a<=5)
	printf("0");
	else if(a>5 && a<13)
	printf("%d",b/2);
	else if(a>=13)
	printf("%d",b);

return 0;
}



Measured memory_bytes: 128
n = int(input())
a = list(map(int, input().split()))
b = 0
ans = 0
dic = {}
for i in a:
    if i not in dic.keys():
        dic[i] = 1
    else:
        dic[i] += 1
for i in dic.values():
    ans += i*(i-1)//2
for i in a:
    print(ans - (dic[i] - 1))

Measured memory_bytes: 24748
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

int my_abs(int num){
   if (num > 0)
      return num;
   else
      return -num;
}

int main(){
    int N;
    cin >> N;
    if(N==1){
        cout << "1" << endl;
    }
    else if(N>=2 && N <4){
        cout << "2" << endl;
    }
    else if(N >= 4 && N < 8){
        cout << "4" << endl;
    }
    else if(N >=8 && N < 16){
        cout << "8" << endl;
    }
    else if(N>=16 && N < 32){
        cout << "16" << endl;
    }
    else if(N>=32 && N < 64){
        cout << "32" << endl;
    }
    else{
        cout << "64" << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x&&x <= b; }
template<class T> void amin(T &a, T v) { if (a > v) a = v; }
template<class T> void amax(T &a, T v) { if (a < v) a = v; }
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS*max(1.0, max(fabs(x), fabs(y))); }
double SQSUM(double x, double y) { return x*x + y*y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;


#if 1
int main()
{
	int n,m;
	cin >> n >> m;

	vector < vector < int > > a(n, vector <int> (m));

	for (int i = 0; i < n; ++i)
	{
		for (int k = 0; k < m; ++k)
		{
			cin >> a[i][k];
			a[i][k]--;
		}
	}

	for (int ans=1; ans<=n; ans++)
	{
		vector <bool> kaisai(m, true);
		vector <int> rank(n);	// NG 決定

		while(1)
		{
			// かならず開催される競技を選んだことにする。
			vector <int> freq(m);
			for (int i = 0; i < n; ++i)
			{
				int k = a[i][rank[i]];
				if(kaisai[k])
				{
					freq[k]++;
				}
			}

			// すべてのfreq[]

			// もしansを超える人気競技があれば、その競技は選べない。
			bool ok = true;
			for (int k = 0; k < m; ++k)
			{
				if (freq[k] > ans)
				{
					ok = false;
					kaisai[k] = false;
				}
			}

			if(ok)
			{
				cout << ans << endl;
				return 0;
			}

			// 全員
			// 人気すぎる競技を選んだ人→希望rankさげる。
			for (int i = 0; i < n; ++i)
			{
				while(kaisai[ a[i][rank[i]] ]==false)
				{
					rank[i]++;
					if (rank[i] >= m)
					{
						goto MURI;
					}
				}
			}
		}

		MURI:;
	}

	return 0;
}



#else

ll gcd(ll x, ll y)
{
	if (x == 0) return y;
	if (y == 0) return x;

	ll t;

	while (y != 0)
	{
		t = x%y;
		x = y;
		y = t;
	}
	return x;
}

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

	vector <int> a(n);

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

	int mx = *max_element(a.begin(),a.end());

	ll g = a[0];
	for (int i = 1; i < n; ++i)
	{
		g = gcd(g, a[i]);
	}

	if (k <= mx && k%g == 0)
	{
		cout << "POSSIBLE" << endl;
	}
	else
	{
		cout << "IMPOSSIBLE" << endl;
	}

	return 0;
}

#endif

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

ll dp[3001][3001]; vector<int> v;

int main() {
	int n; cin >> n; v.resize(n);
	for (auto &x : v) { cin >> x; }
	for (int i = 0; i < n; i++) dp[i][i] = v[i];

	for (int i = 1; i < n; i++) for (int j = 0; j < n - i; j++)
		dp[j][j + i] = max(v[j] - dp[j + 1][j + i], v[j + i] - dp[j][j + i - 1]);

	cout << dp[0][n - 1] << '\n'; cin.ignore(2); return 0;
}

Measured memory_bytes: 49724
import collections
import heapq

x,y,z,t = map(int, raw_input().split(' '))
xs = map(int,raw_input().split(' '))
xs.sort(key = lambda x:-x)
ys = map(int,raw_input().split(' '))
ys.sort(key = lambda x:-x)
zs = map(int,raw_input().split(' '))
zs.sort(key = lambda x:-x)
mat = [xs,ys,zs]
heap = [(-mat[0][0]-mat[1][0]-mat[2][0], 0,0,0)]
seen = set([(0,0,0)])
res = []
while(heap and t):
	u,i,j,k = heapq.heappop(heap)
	print -u
	res.append(-u)
	t-=1
	for nei in [(i+1,j,k), (i,j+1,k), (i,j,k+1)]:
		if nei not in seen and all([0<=nei[ii]<len(mat[ii]) for ii in range(3)]):
			seen.add(nei)
			vv = mat[0][nei[0]] + mat[1][nei[1]] + mat[2][nei[2]]
			vv *= -1
			heapq.heappush(heap,(vv,nei[0],nei[1],nei[2]))


Measured memory_bytes: 37228
#include <cstdio>
#include <iostream>
#include <cstring>
#include <map>
#include <set>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <stack>
#include <ctime>
#include <string>
#include <vector>
#include <sstream>
#include <functional>
#include <algorithm>
using namespace std;

#define mem(a,n) memset(a,n,sizeof(a))
#define memc(a,b) memcpy(a,b,sizeof(b))
#define rep(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
#define IO ios::sync_with_stdio(false)
#define fre freopen("in.txt","r",stdin)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long ll;
typedef unsigned long long ull;
const double PI=acos(-1.0);
const double eps=1e-8;
const int INF=0x3f3f3f3f;
const int MOD=1e8;
const int N=1e4+5;
const ll maxn=5e4;
const int dir[4][2]= {-1,0,1,0,0,-1,0,1};
ll gcd(ll a,ll b)
{
    return b?gcd(b,a%b):a;
}
ll a[N],b[N];
int main()
{
    IO;
    int n;
    while(cin>>n)
    {
        rep(i,0,n) cin>>a[i];
        rep(i,0,n) cin>>b[i];
        ll sum=0;
        rep(i,0,n)
        {
            if(a[i]>b[i]) sum-=a[i]-b[i];
            else sum+=(b[i]-a[i])/2;
        }
        if(sum>=0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    map<int,int>m;
    for(int x=1;x<=100;x++){
        for(int y=1;y<=100;y++){
            for(int z=1;z<=100;z++){
                m[x*x + y*y + z*z + x*y + y*z + z*x]++;
            }
        }
    }
    for(int i=1;i<=n;i++){
        cout << m[i]<<endl;
    }
}

Measured memory_bytes: 5332
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ll n,i,w=0,r=0,ans=0;
	string s;
	cin>>n;
	cin>>s;
	for(i=0;i<n;i++)
	{
		if(s[i]=='W')
		w++;
		else
		r++;
	}
	
	for(i=0;i<r;i++)
	{
		if(s[i]!='R')
		ans++;
	}
	cout<<ans;
}


Measured memory_bytes: 3724
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n;
    if (1000 <= n && n <= 1998) cout << "ABD" << endl;
    else cout << "ABC" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define mem(x, y) memset(x, y, sizeof(x))
#define pii pair<int, int>
#define mkp make_pair
int n, p;

int main()
{
    LL zero = 0, one = 0;
    scanf("%d%d", &n, &p);
    for(int i = 0; i < n; i++) {
        int x; scanf("%d", &x);
        if(x & 1) {
            LL res = one;
            one += zero + 1;
            zero += res;
        }
        else {
            one = one * 2;
            zero = zero * 2 + 1;
        }
    }
    printf("%lld\n", p ? one : zero + 1);
    return 0;
}



Measured memory_bytes: 256
// ARC080-D
#include <bits/stdc++.h>
using namespace std;

int H, W, N;
int a[10010];
int B[109][109];

int main() {
   cin >> H >> W >> N;
   int idx = 0;
   for (int i = 0; i < N; i++) {
      int x;
      cin >> x;
      for (int j = 0; j < x; j++) {
         a[idx] = i+1;
         idx++;
      }
   }

   idx = 0;
   for (int i = 0; i < H; i++) {
      if (i%2==0) {
         for (int j = 0; j < W; j++) {
            B[i][j] = a[idx];
            idx++;
         }
      } else {
         for (int j = W-1; j >= 0; j--) {
            B[i][j] = a[idx];
            idx++;
         }
      }
   }

   // cerr << endl;
   for (int i = 0; i < H; i++) {
      for (int j = 0; j < W-1; j++) {
         cout << B[i][j] << " ";
      }
      cout << B[i][W-1] << endl;
   }

   return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define p pair<int,int>
template<class T> void chmax(T& a, T b){if(a < b) a = b;}
template<class T> void chmin(T& a, T b){if(a > b) a = b;}
int N, M;
int num[100010];
int mod[100010];
int main(){
    cin >> N >> M;
    for(int i = 0; i < N; i++){
        int X;
        cin >> X;
        num[X]++;
        mod[X % M]++;
    }
    int ans = 0;
    for(int i = 1; i < (M + 1) / 2; i++){
        int mini = min(mod[i], mod[M - i]); 
        ans += mini;
        mod[i] -= mini;
        mod[M - i] -= mini;
    }

    ans += mod[0] / 2;
    mod[0] %= 2;

    if(M % 2 == 0){
        ans += mod[M / 2] / 2;
        mod[M / 2] %= 2;
    }

    for(int i = 1; i <= 1e5; i++){
        int mini = min(num[i] / 2, mod[i % M] / 2);
        ans += mini;
        mod[i % M] -= mini * 2;
    }

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

Measured memory_bytes: 1024
#include<iostream>
 int main(){
 	int n=0,a=0,b=0;
 	  std::cin>>n;
 	  if(n==1){
 	    std::cout << "Hello World" << std::endl;
 	  }
 	 else if (n==2){
 	    std::cin>>a;
	    std::cin>>b;
	    std::cout<<a+b<<std::endl;
	  }
	  else{
	    //do nothing
	  }
	  return 0;
	}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main(void){
	int n;
	int box[200];
	int i;
	int cnt;
	int flg;
	scanf("%d",&n);
	for(i=0;i<n;i++)	scanf("%d",&box[i]);
	cnt=0;
	flg=0;
	while(1){
		for(i=0;i<n;i++){
			if(box[i]%2!=0){
				flg=1;
				break;
			}
		}
		if(flg==1)	break;
		for(i=0;i<n;i++)box[i]/=2;
		cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}
	

Measured memory_bytes: 128
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    int n; cin >> n;
    cout << (n+1)/2 << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

#define mod 1000000007

long long div(long long n,long long a){
	if(n==1)return a;
	if(n%2==0){
		long long i=div(n/2,a);
		return (i*i)%mod;
	}
	return a*div(n-1,a)%mod;
}

int main(){
	int n,k,i;
	long long ans[2001]={0},pp[2001]={1},pp2[2001]={1},kai[2001]={1};
	scanf("%d%d",&n,&k);
	if(n==k){
		puts("1");
		for(i=1;i<k;i++)puts("0");
		return 0;
	}
	for(i=1;i<k;i++)pp[i]=(pp[i-1]*(k-i))%mod;
	for(i=1;i<n-k;i++)pp2[i]=(pp2[i-1]*(n-k-i))%mod;
	for(i=1;i<=n;i++)kai[i]=(kai[i-1]*i)%mod;
	for(i=1;i<=k;i++){
		ans[i]=(pp[i-1]*div(mod-2,kai[i-1]))%mod;
		long long red=0;
		if(i>1)red=pp2[i-2]*div(mod-2,kai[i-2]);
		red%=mod;
		red+=(2*(pp2[i-1]*div(mod-2,kai[i-1])))%mod;
		red+=((pp2[i]*div(mod-2,kai[i])))%mod;
		red%=mod;
		ans[i]*=red;
		ans[i]%=mod;
	}
	for(i=1;i<=k;i++)printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 256
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>
#include <list>
#include <random>

// macros
#define ll long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

// solve
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;}

bool a[10];

int main(int argc, char const* argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  for(int i = 0; i < 4; i++){
    int n;
    cin >> n;
    a[n] = true;
  }
  if(a[1] && a[9] && a[7] && a[4])cout << "YES" << endl;
  else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define mod 1000000007 //1e9+7
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 30

int mm[SIZE][SIZE];
int w,h;

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

int dfs(int y,int x,int depth = 0){
  int ret = INF;

  if(depth >= 10) return INF;
  
  //
  for(int i=0;i<4;i++){
    int tx = x + dx[i];
    int ty = y + dy[i];
    
    if(ty<0 || h<=ty || tx<0 || w<=tx || mm[ty][tx]==1) continue;

    if(mm[ty][tx]==3) return depth+1;
    
    while(1){
      tx += dx[i];
      ty += dy[i];
      
      if(ty<0 || h<=ty || tx<0 || w<=tx) break;
      
      if(mm[ty][tx]==3) return depth+1;

      if(mm[ty][tx]==1){
	mm[ty][tx] = 0;
	ret = min(ret,dfs(ty-dy[i],tx-dx[i],depth+1));
	mm[ty][tx] = 1;
	break;
      }
    }

  }

  return ret;
}

int calc(){
  int sy,sx;
  
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      scanf("%d",mm[i]+j);
      if(mm[i][j]==2){
	sy = i;
	sx = j;
      }
    }
  }

  int ans = dfs(sy,sx);
  
  if(ans==INF) ans = -1;
  
  return ans;
}

int main(){

  while(1){
    scanf("%d%d",&w,&h);
    if(w==0) break;
    printf("%d\n",calc());
  }

  
  return 0;
}

Measured memory_bytes: 3084
#include<stdio.h>


int main( void )
{
	int N ;
	while( scanf( "%d" ,&N ) != EOF )
	{
		long cnt[ 4 + 1 ][ 50 + 1 ] = { 1 } ;

		int i ,j ,k ;
		for( i = 1 ; i <= 4 ; ++i )
		{
			for( j = 0 ; j <= N ; ++j )
			{
				if( cnt[ i - 1 ][ j ] > 0 )
				{
					for( k = 0 ; k <= 9 ; ++k )
					{
						if( j + k < 50 + 1 )
						{
							cnt[ i ][ j + k ] += cnt[ i - 1 ][ j ] ;
						}
					}
				}
			}
		}

		printf( "%ld\n" ,cnt[ 4 ][ N ] ) ;
	}

	return 0 ;
}


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

using namespace std;

using lint = long long;

#define MOD_NUMBER 1000000007

template <class T> void vector_print(vector<T> vec) {
  for (unsigned int i = 0; i < vec.size(); i++) {
    cout << vec.at(i);
    if (i < vec.size()-1) {
      cout << " ";
    } else if (i == vec.size()-1) {
      cout << endl;
    }
  }
}

int main() {
  lint a, b, c, d, taka, aoki;
  cin >> a >> b >> c >> d;
  taka = c%b ? c/b+1 : c/b;
  aoki = a%d ? a/d+1 : a/d;
  if (taka > aoki) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 3596
import math
N, D = (int(i) for i in input().split())
e = [[int(i) for i in input().split()] for i in range(N)]
count = 0
for i in range(N):
    for j in range(i+1, N):
        total = 0
        for k in range(D):
            total += (e[i][k]-e[j][k])**2
        if math.sqrt(total).is_integer():
            count +=1

print(count)


Measured memory_bytes: 38384
#pragma GCC optimize("Ofast")
#include <iostream>
#include <cmath>
#include <bits/stdc++.h>
#include <set>
#include <string>
#include <cstring>
#include <string>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define FIXED_FLOAT(x)  std::fixed <<std::setprecision(7)<<(x)
#define MAX 100
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INF 1e9
#define ll long long
#define vi vector<int>
#define all(a) a.begin(), a.end()
#define pb push_back
#define ull unsigned long long


using namespace  std;

void sol() {
    int n,m,x;
  cin >>n >>m >>x;
  int a[12][12];
  vector<int> c(n);
  rep(i,n){
    cin >>c[i];
    rep(j,m) cin >>a[i][j];
  }
  int ans = 1001001001;
  rep(s,1<<n){
    int cost = 0;
    vector<int> d(m);
    rep(i,n){
      if(s>>i&1){
        cost += c[i];
        rep(j,m) d[j] += a[i][j];
      }
    }
    bool ok = true;
    rep(j,m) if(d[j]<x) ok = false;
    if(ok) ans = min(ans,cost);
  }
  if(ans==1001001001) cout << -1 << endl;
  else cout << ans << endl;
}


int main() {
    fast;
    sol();


}




Measured memory_bytes: 3660
s=list(input())
t=list(input())
cnt=0
total=0
big=len(t)
for i in range(0,len(s)-len(t)+1):
    for j in range(len(t)):
        if s[i]!=t[j]:
            total+=1
        i+=1
        if j==len(t)-1:
            big=min(big,total)
            total=0

print(big)

Measured memory_bytes: 8992
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <queue>
#include <stdarg.h>
#include <map>
#include <vector>
#include <algorithm>
#include <stack>
#include <iostream>
#include <numeric>
#include <set>

#define ll long long

using namespace std;

void
solve() {
  ll h, w, k;
  cin>>h>>w>>k;

  vector<string> c(h, "");
  for (ll i=0; i<h; i++)
    cin>>c[i];

  ll ans = 0;
  for (ll row=0; row<(1<<h); row++) {
    for (ll col=0; col<(1<<w); col++) {

      ll cnt = 0;
      for (ll i=0; i<h; i++)
        for (ll j=0; j<w; j++) 
          if (c[i][j] == '#' && (row & (1<<i)) && (col & (1<<j)))
            cnt++;
      if (cnt == k)
        ans++;
    }
  }
  cout<<ans<<endl;
}

int 
main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);

  int t = 1;
  //cin>>t;

  while (t > 0) {
    t--;
    solve();
  }

  return 0;
}



Measured memory_bytes: 3672
import copy
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def is_nth_bit_set(x, n):
    if x & (1 << n):
        return True
    else:
        return False


def count(c, H, W):
    res = 0
    for h in range(H):
        for w in range(W):
            if c[h][w] == "#":
                res += 1

    return res


def main():
    H, W, K = map(int, input().split())
    C = [list(input()) for _ in range(H)]

    ans = 0
    for h_pattern in range(2 ** H):
        for w_pattern in range(2 ** W):
            tmp = copy.deepcopy(C)

            for h in range(H):
                if not is_nth_bit_set(h_pattern, h):
                    continue

                for w in range(W):
                    tmp[h][w] = "r"

            for w in range(W):
                if not is_nth_bit_set(w_pattern, w):
                    continue

                for h in range(H):
                    tmp[h][w] = "r"

            c = count(tmp, H, W)
            if c == K:
                ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9348
#include <stdio.h>
#include <string.h>
#define N 500000
int count;
 
struct node
{
  int key;
  int pare;
  int l;
  int r;
};
 
struct node bi[N];
 
void insert(int z)
{
  int x,y;
  int num = 0;
 
  y = -1;
  x = bi[0].key;

  while(1)
  {
    if(x==-1)break;

    y = num;

    if(z<x)
    {
      num = bi[num].l;
      if(num!=-1)x = bi[num].key;
      else
      {
        x = -1;
      }
    }
    else
    {
      num = bi[num].r;
      if(num != -1)x = bi[num].key;
      else
      {
        x = -1;
      }
    }
  }

  bi[count].pare=y;
  bi[count].key=z;
 
  if(y==-1)
  {
    bi[0].key=z;
  }
  else if(z < bi[y].key)
  {
    bi[y].l = count;
  }
  else
  {
    bi[y].r = count;
  }
 
  count++;
}
 
void pre(int now)
{
  printf(" %d",bi[now].key);
  if(bi[now].l != -1)  pre(bi[now].l);
  if(bi[now].r != -1)  pre(bi[now].r);
}
 
void in(int now)
{
  if(bi[now].l != -1)in(bi[now].l);
  printf(" %d",bi[now].key);
  if(bi[now].r != -1)in(bi[now].r);
}
 
 
void print()
{
  in(0);
  printf("\n");
  pre(0);
  printf("\n");
}
 
void find(int key)
{
  int i = 0;
  while(1)
  {
    if(bi[i].key == key)
    {
      printf("yes\n");
      return;
    }
    if(bi[i].pare == -1)break;
    i = bi[i].pare;
  }

  while(1)
  {
    if(bi[i].key < key)
    {
      i = bi[i].r;
      if(i == -1)
      {
        printf("no\n");
        return;
      }
    }
    else
    {
      i = bi[i].l;
      if(i == -1)
      {
        printf("no\n");
        return;
      }
    }
    if(bi[i].key == key)
    {
      printf("yes\n");
      return;
    }
  }
}
 
int main(void)
{
  int n,i;
  int num;
  char comm[10];
  count=0;
 
  for(i = 0;i < N;i++)
  {
    bi[i].key = -1;
    bi[i].pare = -1;
    bi[i].l = -1;
    bi[i].r = -1;
  }

 
  scanf("%d",&n);
 
  for(i = 0;i < n;i++)
  {

    scanf("%s",comm);

    if(strcmp(comm,"insert") == 0)
    {

      scanf("%d",&num);
      insert(num);
    }
    else if(strcmp(comm,"find") == 0)
    {
      scanf("%d",&num);
      find(num);
    }
    else
    {
      print();
    }
  }
  return 0;
}

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

namespace ConsoleApp15
{
    class Class205
    {
        static void Main()
        {
            string S = Console.ReadLine();
            if (S[2] == S[3] && S[4] == S[5]) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<int>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int main(){
  int n,k,l;
  cin >> n >> k >> l;
  UnionFind h(n);
  UnionFind w(n);
  rep(i,k){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    h.unionSet(a,b);
  }
  rep(i,l){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    w.unionSet(a,b);
  }
  map<pair<int,int>,int> m;
  rep(i,n){
    m[make_pair(h.root(i),w.root(i))]++;
  }
  rep(i,n){
    cout << m[make_pair(h.root(i),w.root(i))];
    if(i!=n-1)cout << " ";
    else cout << endl;
  }
}


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

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#pragma GCC optimize("Ofast")
//1.0 * clock() / CLOCKS_PER_SEC

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const ll NN = 1e10 + 7;
const int N = 1e5 + 7;
const int M = 11;
const ll mod = 1e9 + 7;
const ll inf = 1e18 + 7;
const dl rf = 1e-14;
const int B = sqrt(N);

void solve1()
{
    int n;
    string s;
    cin >> n >> s;
    ll ans = 0;
    map < char , int > m;
    m['R'] = 0;
    m['B'] = 1;
    m['G'] = 2;
    for( int i = 0; i < n; i++ ){
        vector < vector < int > > v(3);
        v[m[s[i + 1]]].push_back(i + 2);
        for( int j = i + 2; j < n; j++ ){
            int id = 0;
            for( auto x : m ){
                if( x.fi != s[i] && x.fi != s[j] ){
                    id = x.se;
                    break;
                }
            }
            if( s[i] != s[j] && !v[id].empty() ){
                int l = 0 , r = (int)v[id].size() - 1;
                while( l < r ){
                    int mm = (l + r) / 2;
                    if( v[id][mm + 1] * 2 > i + j + 2 )r = mm;
                    else l = mm + 1;
                }
                ans += (ll)( (ll)v[id].size() - (v[id][l] * 2 == i + j + 2) );
            }
            v[m[s[j]]].push_back(j + 1);
        }
    }
    cout << ans;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


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

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()

#define MOO(i, a, b) for(int i=a; i<b; i++)
#define M00(i, a) for(int i=0; i<a; i++)
#define MOOd(i,a,b) for(int i = (b)-1; i >= a; i--)
#define M00d(i,a) for(int i = (a)-1; i>=0; i--)

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << '\n', 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _ << " _ " <<

template<class T> bool ckmin(T& a, const T& b) {return b < a ? a = b, 1 : 0;}
template<class T> bool ckmax(T& a, const T& b) {return a < b ? a = b, 1 : 0;}

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ld,ld> pd;
typedef complex<ld> cd;

const int MAX_N = 5050;
int n; ll k;
int to[MAX_N];
ll cost[MAX_N];

int main() { FAST
    cin >> n >> k;
    M00(i, n) {
        cin >> to[i];
        to[i]--;
    }
    M00(i, n) cin >> cost[i];
    ll ans = -1e18;
    M00(i, n) {
        vector<bool> vis(n, 0);
        int cur = i;
        int t = 0;
        vi tail;
        vi cycle;
        int cyclestart = -1;
        ll ctr = 0;
        ll curmx = -1e18;
        M00(j, k) {
            cur = to[cur];
            if(vis[cur]) {
                cyclestart = cur;
                break;
            }
            ctr += cost[cur];
            ckmax(curmx, ctr);
            vis[cur] = 1;
        }
        if(cyclestart == -1) {
            ckmax(ans, curmx);
            continue;
        }
        cur = i;
        while(1) {
            cur = to[cur];
            if(cur == cyclestart) break;
            tail.pb(cur);
        }
        while(1) {
            cycle.pb(cur);
            cur = to[cur];
            if(cur == cyclestart) break;
        }
        ctr = 0;
        curmx = -1e18;
        for(int u: tail) {
            ctr += cost[u];
            ckmax(curmx, ctr);
        }
        for(int u: cycle) {
            ctr += cost[u];
            ckmax(curmx, ctr);
        }

        ll cyclelen = 0;
        ll tot = 0;
        for(int u: cycle) cyclelen += cost[u];
        if(cyclelen <= 0) {
            tot = curmx;
            ckmax(ans, curmx);
        } else {
            for(int u: tail) tot += cost[u];
            int numMovesInCycle = k-sz(tail);
            tot += cyclelen*max(0,(numMovesInCycle/sz(cycle)));
            ll curmx2 = tot;
            int last = numMovesInCycle%(sz(cycle));
            if(last == 0) {
                last = sz(cycle);
                tot -= cyclelen;
            }
            M00(j, last) {
                tot += cost[cycle[j]];
                ckmax(curmx2, tot);
            }
            ckmax(ans, max(curmx, curmx2));
        }
    }
    finish(ans);
}



Measured memory_bytes: 3692
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner scan = new Scanner(System.in);
		
		//BigDecialでdoubleから生成すると誤差が出るのでNG
		//使うときは".valueOf()"を使う
		String a = scan.next();
		String b = scan.next();
		
		BigDecimal a1 = new BigDecimal(a);
		BigDecimal b1 = new BigDecimal(b);
		
		BigDecimal answer = a1.multiply(b1);
		
		//小数点以下切り捨て
		answer = answer.setScale(0, RoundingMode.DOWN);	
		
		
		System.out.println(answer);
		
		}

}


Measured memory_bytes: 35824
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
const long long MOD = (long long)1e9 + 7;

long long n, mi = 1e18;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < 5; i++) {
		long long tmp;
		cin >> tmp;
		mi = min(mi, tmp);
	}
	cout << (n + (mi - 1)) / mi + 4 << "\n";
	//system("pause");
	return 0;
}

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

int main() {
    ll K, A, B;
    cin >> K >> A >> B;
    ll ans = 1 + K;
    ll need = A - 1;
    ll tmp = 0;
    ll rest = K - need;
    tmp += (B - A) * (rest / 2) + A;
    if(rest & 1) tmp++;
    cout << max(tmp, ans) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){
  char s1[11], s2[11], s3[11];

  scanf("%s%s%s", s1, s2, s3);

  printf("%c%c%c", s1[0]+('A' - 'a'), s2[0]+('A' - 'a'), s3[0]+('A' - 'a') );
  printf("\n");
  
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>

using namespace std;

int main() {

	int c[3][3];

	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> c[i][j];
		}
	}

		if (c[0][0] - c[1][0] != c[0][1] - c[1][1] || c[0][1] - c[1][1] != c[0][2] - c[1][2]) {
			cout << "No";
			return 0;
		}
		if (c[1][0] - c[2][0] != c[1][1] - c[2][1] || c[1][1] -c[2][1] != c[1][2] - c[2][2]) {
			cout << "No";
			return 0;
		}
		if (c[2][0] - c[0][0] != c[2][1] - c[0][1] || c[2][1] - c[0][1] != c[2][2] - c[0][2]) {
			cout << "No";
			return 0;
		}
		cout << "Yes";

	return 0;
}

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

typedef enum {
    FALSE,
    TRUE
} bool_t;

bool_t cache[1000000];

bool_t isPrime ( int input )
{
    int i;

    if ( input <= 1 )
        return FALSE;

    for ( i = 2; i <= sqrt(input); i++ )
    {
        if ( input % i == 0 )
            return FALSE;
    }

    return TRUE;
}

void create_table ( void )
{
    int i;
    for ( i = 1; i < 1000000; i++ )
    {
        cache[i] = isPrime( i );
    }
}

int main ( void )
{
    int counter, input, i = 0;

    create_table();

    while ( scanf( "%d", &input ) != EOF )
    {
        counter = 0;
        for ( i = 2; i <= input; i++ )
        {
            if ( cache[i] )
                counter++;
        }
        printf("%d\n", counter );
    }

    return 0;
}

Measured memory_bytes: 4500
# -*- coding: utf-8 -*-

import sys

def parse_input(lines_as_string = None):

    lines = []
    if lines_as_string is None:
        lines.append(input())
        tokens = lines[0].split(" ")
        n = int(tokens[0])
        m = int(tokens[1])
        for i in range(n):
            lines.append(input())
    else:
        lines = [e for e in lines_as_string.split("\n")][1:-1]
        print("lines=%s" % lines)
        tokens = lines[0].split(" ")
        n = int(tokens[0])
        m = int(tokens[1])

    a = []
    b = []
    for i in range(n):
        tokens = lines[i+1].split(" ")
        a.append(int(tokens[0]))
        b.append(int(tokens[1]))

    return (n, m, a, b)

def solve(n, m, a, b):

    
    s_a = sorted([(i, e) for i, e in enumerate(a)], key=lambda e: e[1])
#    print("s_a=%s" % s_a)

    current = m
    total = 0
    tmp = 0
    for i, e in s_a:
        if current > b[i]:
            tmp = e * b[i]
            current = current - b[i]
        else:
            tmp = e * current
            current = 0

        total = total + tmp

#        print("i=%d, total=%d" % (i, total))
        if current == 0:
            break

    return total

def main():

    print("%d" % solve(*parse_input()))

if __name__ == '__main__':

    main()


Measured memory_bytes: 23476
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(int i=0;i<n;i++)
#define Rip(i,n) for(int i=1;i<=n;i++)
#define RIP(i,a,b) for(int i=a;i<b;i++)
#define all(V) V.begin(),V.end()
#define sec  setprecision;
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops");
constexpr double eps = 1e-9;
constexpr double pi = 3.141592653589793238462643383279;
using ll = long long;
using ld = long double;
using Pa = std::pair<ll, ll>;
using namespace std;
ll gcd(ll a, ll b)
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
ll pow(ll x, ll n,ll mod) {
	x %= mod;
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return (pow(((x * x)%mod), n / 2,mod));
	else
		return ((x%mod) * pow(x, n - 1,mod));
}
vector<ll>primess(ll n) {
	vector<ll>a;
	while (n % 2 == 0)n /= 2, a.push_back(2);
	ll sosuu = 3;
	while (n != 1) {
		if (n % sosuu == 0)n /= sosuu, a.push_back(sosuu);
		else if (sosuu > sqrt(n) + 2) {
			a.push_back(n);
			break;
		}
		else sosuu += 2;
	}
	return a;
}
bool prime(int n) {
	int i = 2;
	if (n == 2)return true;
	else if(n <= 1)return false;
	if (n % i == 0)return false;
	i = 3;
	while (i <= sqrt(n)) {
		if (n % i == 0)return false;
		i += 2;
	}
	return true;
}
int main() {
	int n; cin >> n;
	ll count = 0;
	vector<int>a(n);
	rip(i, n)cin >> a[i];
	rip(i, n) {
		for (int j = i + 1; j < n; j++) {
			for (int k = j + 1; k < n; k++) {
				if (a[i] != a[j] && a[i] != a[k] && a[j] != a[k]) {
					ll num = a[i] + a[j] + a[k] - max({ a[i],a[j],a[k] });
						if (num > max({ a[i],a[j],a[k] }))count++;
				}
			}
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;
const double PI = acos(-1);

int main(){
  int h,w,k; cin >> h >> w >> k;

  vector<string> g(h);
  for(int i = 0; i < h; i++) cin >> g[i];

  int ans = 0;
  for(int bit = 0; bit < 1<<h; bit++){
    for(int bit2 = 0; bit2 < 1<<w; bit2++){
      int c = 0;
      for(int i = 0; i < h; i++){
        if(bit >> i & 1) continue;
        for(int j = 0; j < w; j++){
          if(bit2 >> j & 1) continue;
          if(g[i][j] == '#') c++;
        }
      }
      if(c == k) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628