akhauriyash/Code-Regression huggingface dataset:
from functools import reduce
from operator import mul

def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    return reduce(mul, range(n, n - r, -1)) // reduce(mul, range(r, 0, -1))
ans = 0
n = int(input())
s = [input() for i in range(n)]
anagram = {}
for i in s:
  t = [0] * 26
  for j in i:
    t[ord(j)-ord("a")] += 1
  t = "".join(map(str, t))
  if t in anagram:
    anagram[t] += 1
  else:
    anagram[t] = 1
for i in anagram.values():
  if i >= 2:
    ans += cmb(i, 2)
print(ans)

Measured memory_bytes: 26972
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [float("inf") for i in range(n+k+10)]
dp[0] = 0

for i in range(n-1):
    for j in range(1,k+1):
        if i+j >= n:
            continue
        dp[i+j] = min(dp[i+j], dp[i] +abs(h[i]-h[i+j]))

print(dp[n-1])

Measured memory_bytes: 56928
import math, operator
from collections import Counter
from itertools import chain, product, permutations, combinations
from functools import reduce, lru_cache
class PrimeUtils:
    @staticmethod
    def primes_sieve(n):
        sieve = [True] * (n + 1)
        for i in range(2, n + 1):
            if sieve[i]:
                for j in range(i + i, n + 1, i):
                    sieve[j] = False
        return [i for i, x in enumerate(sieve[2:], 2) if x]
    @classmethod
    # Prime Factor Decomposition
    def pfd(cls, n):
        rn = math.ceil(math.sqrt(n))
        primes = cls.primes_sieve(rn)

        factors = []
        cur = n
        for p in primes:
            while True:
                div, rem = divmod(cur, p)
                if rem == 0:
                    factors.append(p)
                    cur = div
                else:
                    break
        if cur != 1 or not factors:
            factors.append(cur)
        return factors
    @classmethod
    # List up aliquots
    def aliquots(cls, n):
        pf = cls.pfd(n)
        pfc = Counter(pf)
        ppv = [[pow(p, i) for i in range(n+1)] for p,n in pfc.items()]
        return map(lambda x: reduce(operator.imul, x), product(*ppv))

N, M = map(int, input().split())
print(M // min(filter(lambda a: N <= a, PrimeUtils.aliquots(M))))

Measured memory_bytes: 4172
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    string s,t;
    cin>>s>>t;
    int ans=t.size();
    for(int i=0;i<=(s.size()-t.size());++i){
        int diff = 0;
        for(int j=0;j<t.size();++j){
            if(t[j]!=s[i+j]){
                diff++;
            }
        }
        ans=min(ans,diff);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3596
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Data.List
import Control.Monad
import Data.Ord

r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine



main :: IO ()
main = do
    r <- readLn
    print $ 2*pi*r


Measured memory_bytes: 3960
#include<bits/stdc++.h>
#define pls(x,y) (x+=y)>=M?x-=M:0
using namespace std;
const int N=100005,M=1000000007;
int n,m,t,a[N],b[N],x,ans=1;
set<int>S;
set<int>::iterator it;
struct dat{
	int x,y;
}p[N];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
	scanf("%d",a+i);
	for(;m--;)
	scanf("%d",&x),S.insert(x);
	for(int i=0;i<n;i++){
		it=S.upper_bound(a[i]);
		if(it!=S.end()&&it!=S.begin())
		p[t].y=*it-a[i],p[t++].x=a[i]-*--it;
	}
	sort(p,p+t,[](dat a,dat b){return a.y<b.y;});
	for(int i=x=0;i<t;i++)
	x=(i?p[i-1].y:0)+(p[i].y>x),swap(x,p[i].y);
	n=p[t-1].y;
	sort(p,p+t,[](dat a,dat b){return a.x^b.x?a.x<b.x:a.y>b.y;});
	for(int i=0;i<t;i++)
	if((!i)||p[i].x!=p[i-1].x||p[i].y!=p[i-1].y){
		x=1;
		for(int j=p[i].y-1;j;j-=j&-j)
		pls(x,b[j]);
		pls(ans,x);
		for(int j=p[i].y;j<=n;j+=j&-j)
		pls(b[j],x);
	}
	printf("%d",ans);
}

Measured memory_bytes: 6272
#![allow(unused_imports)]
#![allow(non_snake_case, unused)]

use std::cmp::*;
use std::collections::*;
use std::ops::*;

// https://atcoder.jp/contests/hokudai-hitachi2019-1/submissions/10518254

macro_rules! eprint {
    ($($t:tt)*) => {{
        use ::std::io::Write;
        let _ = write!(::std::io::stderr(), $($t)*);
    }};
}
macro_rules! eprintln {
    () => { eprintln!(""); };
    ($($t:tt)*) => {{
        use ::std::io::Write;
        let _ = writeln!(::std::io::stderr(), $($t)*);
    }};
}
macro_rules! dbg {
    ($v:expr) => {{
        let val = $v;
        eprintln!("[{}:{}] {} = {:?}", file!(), line!(), stringify!($v), val);
        val
    }}
}

macro_rules! mat {
    ($($e:expr),*) => { Vec::from(vec![$($e),*]) };
    ($($e:expr,)*) => { Vec::from(vec![$($e),*]) };
    ($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };
    ($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };
}

macro_rules! ok {
    ($a:ident$([$i:expr])*.$f:ident()$(@$t:ident)*) => {
        $a$([$i])*.$f($($t),*)
    };
    ($a:ident$([$i:expr])*.$f:ident($e:expr$(,$es:expr)*)$(@$t:ident)*) => { {
        let t = $e;
        ok!($a$([$i])*.$f($($es),*)$(@$t)*@t)
    } };
}

pub fn readln() -> String {
    let mut line = String::new();
    ::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e));
    line
}

macro_rules! read {
    ($($t:tt),*; $n:expr) => {{
        let stdin = ::std::io::stdin();
        let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
            let line = line.unwrap();
            let mut it = line.split_whitespace();
            _read!(it; $($t),*)
        }).collect::<Vec<_>>();
        ret
    }};
    ($($t:tt),*) => {{
        let line = readln();
        let mut it = line.split_whitespace();
        _read!(it; $($t),*)
    }};
}

macro_rules! _read {
    ($it:ident; [char]) => {
        _read!($it; String).chars().collect::<Vec<_>>()
    };
    ($it:ident; [u8]) => {
        Vec::from(_read!($it; String).into_bytes())
    };
    ($it:ident; usize1) => {
        $it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1
    };
    ($it:ident; [usize1]) => {
        $it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>()
    };
    ($it:ident; [$t:ty]) => {
        $it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
    };
    ($it:ident; $t:ty) => {
        $it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
    };
    ($it:ident; $($t:tt),+) => {
        ($(_read!($it; $t)),*)
    };
}


pub fn main() {
    let _ = ::std::thread::Builder::new().name("run".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();
}

const MOD: usize = 1_000_000_007;
const INF: i64 = std::i64::MAX/2;

fn solve() {
    let n = read!(usize);
    let a = read!([i64]);
    let mut base = 0;
    let mut ans = 0;
    for a in a {
        if base > a {
            ans += base-a;
        }
        base = max(base,a);
    }
    println!("{}",ans);
}

fn run() {
    solve();
}


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

int main() {
	int n;
	cin >> n;
	vector<int> A(n);
	Rep(i, n) cin >> A[i];
	int q;
	cin >> q;
	Rep(i, q) {
		int c, b, e;
		cin >> c >> b >> e;
		if (c == 0) {
			cout << *min_element(A.begin() + b, A.begin() + e) << endl;
		}
		else if (c == 1) {
			cout << *max_element(A.begin() + b, A.begin() + e) << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3096
// No sorceries shall prevail. //           
import java.util.*;
import java.io.*;
public class Main {
	
	static long gcd(long a, long b) { 
	      if (b == 0) 
	        return a; 
	      return gcd(b, a % b);  
	    }
	static int gcd(int a, int b) { 
	      if (b == 0) 
	        return a; 
	      return gcd(b, a % b);  
	    }
	
	static long mod = 1000000007;
	public static void main(String args[]) {
		Scanner inp=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		
		int n=inp.nextInt();
		int x=inp.nextInt();
		int y=inp.nextInt();
		int ways[]=new int[n+1];
		for(int i=1;i<n;i++) {
			int z=0;
			for(int j=i+1;j<=n;j++) {
				z=Math.min(j-i, Math.abs(x-i)+1+Math.abs(y-j));
				ways[z]++;
			}
		}
		for(int i=1;i<n;i++) {
			out.println(ways[i]);
		}
		out.close();
		inp.close();
	}
}

Measured memory_bytes: 21204
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<cmath>
#include<ctime>
#include<cassert>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<bitset>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int main()
{	int a,b,c; ll k; cin>>a>>b>>c>>k;
	if(k&1) cout<<b-a<<endl;
	else cout<<a-b<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
 
class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int  num = scanner.nextInt();//階層数
		
		System.out.println( fin(num) );
		 
		scanner.close();
	}
	 
	public static long fin(int num) {
		long Fin0 = 1,Fin1 = 1,Fin = 0;
		
		//この2つだけそのまま
		if( num == 0 ) return 0;
		if( num == 1 ) return 1;
		 
		//フィボナッチ数列
		for(int i = 1; i < num; i ++) {
			Fin = Fin0 + Fin1;
			Fin0 = Fin1;
			Fin1 = Fin;
		}
		 
		return Fin; 
	}
}


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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repd(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
  cout << a;
  ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
  cout << a << ' ';
}

int ans = 0;
bool check = 0;
string s, t;
int N = 3;
vector<int> v(N);
int a, b, c, d;
int x, y;
char ch;

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{
  cin >> a >> b >> c >> d;
  pr(max(a * b, c * d));
}

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

struct Block {
	string s;
	bool overlap(Block b){
		for(int i = 0; i < 4; i++) {
			if(s[i] == '#' && b.s[i] == '#') return true;
		}
		return false;
	}

	void add(Block b){
		for(int i = 0; i < 4; i++) {
			assert(s[i] == '.' || b.s[i] == '.');
			if(b.s[i] == '#') s[i] = '#';
		}
	}

	bool mv(int dx, int dy){
		if(dx == 1) {
			if(s[1] == '#' || s[3] == '#') return false;
			s[1] = s[0], s[3] = s[2];
			s[0] = '.', s[2] = '.';
		}
		if(dx == -1) {
			if(s[0] == '#' || s[2] == '#') return false;
			s[0] = s[1], s[2] = s[3];
			s[1] = '.', s[3] = '.';
		}
		if(dy == 1) {
			if(s[0] == '#' || s[1] == '#') return false;
			s[0] = s[2], s[1] = s[3];
			s[2] = '.', s[3] = '.';
		}
		if(dy == -1) {
			if(s[2] == '#' || s[3] == '#') return false;
			s[2] = s[0], s[3] = s[1];
			s[0] = '.', s[1] = '.';
		}
		return true;
	}
};

const int MAX = 25;
Block initial[MAX];
Block field[MAX];
vector<Block> b[10];
vector<Block> fall[10];
int H, N, ans;

void view(){
	for(int i = 0; i < 3; i++) {
		cout << field[i].s << endl;
	}
	cout << endl;
}

int Fall(vector<Block> t){
	int ret = 0;
	int y = MAX - 2;
	while(y > 0) {
		if(t[0].overlap(field[y - 1]) || t[1].overlap(field[y])) break;
		y--;
	}
	assert(y + 1 < MAX);
	field[y].add(t[0]);
	field[y + 1].add(t[1]);
	//cerr << y << endl;
	//cerr << t[0].s << endl;
	//cerr << t[1].s << endl;

	for(int i = 0; i < MAX; i++) {
		if(field[i].s == "####") {
			ret++;
			for(int j = i + 1; j < MAX - 1; j++) {
				field[j - 1].s = field[j].s;
				field[j].s = "....";
			}
			i--;
		}
	}
	//view();
	return ret;
}

int sim(){
	int ret = 0;
	for(int i = 0; i < N; i++) {
		//cerr << i << endl;
		ret += Fall(fall[i]);
	}
	return ret;
}

void dfs(int n){
	if(n == N) {
		for(int i = 0; i < MAX; i++) {
			field[i] = initial[i];
		}
		ans = max(ans, sim());
		return;
	}
	for(int dx = -1; dx <= 1; dx++) {
		for(int dy = -1; dy <= 1; dy++) {
			fall[n][0].s = b[n][0].s;
			fall[n][1].s = b[n][1].s;
			if(!fall[n][0].mv(dx, dy) || !fall[n][1].mv(dx, dy)) continue;
			dfs(n + 1);
		}
	}
}

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

	for(int i = 0; i < 10; i++) {
		b[i] = vector<Block>(2);
		fall[i] = vector<Block>(2);
	}

	while(cin >> H >> N, N) {
		for(int i = 0; i < MAX; i++) {
			initial[i].s = "....";
		}
		for(int i = 0; i < H; i++) {
			string s1, s2;
			cin >> s1 >> s2;
			initial[i].s = s1 + s2;
		}
		for(int i = 0; i < N; i++) {
			string s1, s2, s3, s4;
			cin >> s1 >> s2 >> s3 >> s4;
			b[i][0].s = s1 + s2;
			b[i][1].s = s3 + s4;
			if(b[i][0].s == "....") {
				swap(b[i][0].s, b[i][1].s);
			}
		}

		ans = 0;
		dfs(0);
		cout << ans << endl;
	}
}

Measured memory_bytes: 3244
from collections import namedtuple
from operator import attrgetter

Number = namedtuple('Number', 'number idx')

n = int(input())

a = []
for idx in range(n):
    k = int(input())
    a.append(Number(number=k, idx=idx))

a.sort(key=attrgetter('number'))

ret = 0
for j, a_ in enumerate(a):
    if (j - a_.idx) % 2 != 0:
        ret += 1
print(ret // 2)


Measured memory_bytes: 66008
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn=1e5+100;
int n, k;
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin>>n>>k;
    cout<<(n-2)/(k-1)+1<<"\n";
    return 0;
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


li n, t;

PI ab[3030];

li dp[6060];

int main() {
    cin >> n >> t;
    rin{
        cin >> ab[i].F >> ab[i].S;
    }
    sort(ab, ab + n);

    li res = 0;
    rin{
        rep(j, t) {
            res = max(res, dp[j] + ab[i].S);
        }
        for (li j = t; j >= ab[i].F; j--) {
            dp[j] = max(dp[j], dp[j - ab[i].F] + ab[i].S);
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 384
a,b,c,k = map(int,input().strip().split())
ans = 0
if k>0:
    ans += min(k,a)
    k -= min(k,a)
if k>0:
    k -= min(k,b)
if k>0:
    ans -= min(k,c)
    k -= min(k,c)
print(ans)

Measured memory_bytes: 9188
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define pii pair<int,int>
#define fi first
#define se second
#define mp(x,y) make_pair(x,y)
#define pb(x) pupsh_back(x)
int32_t main() {
   
   int N;
   cin>>N;
   if(N==2)
   {
       cout<<1;return 0;
   }
   int cnt=0;
   int i=2;
   set<int> ANS;
   for(i=2;i*i<N;i++)
   {
      // int cnt=0;
       int M=N;
       
       if(M%i!=0)
       continue;
       
       while(M%i==0)
       {
           M=M/i;
       }
       
       if(M==1)
       {
           //cout<<i<<" ";
          // cout<<"S";
           cnt++;
          // cout<<i<<" ";
       }
       else if(M%i==1)
       {
          // cout<<i<<" ";
          //  cout<<"Y";
            cnt++;
            //cout<<i<<" ";
            //cout<<N/i<<" ";
            //cout<<cnt;
       }
       
       //M=N;
   }
   
   if(i*i==N) cnt++;
   
   N--;
   
   for(i=2;i*i<N;i++)
   {
      // int cnt=0;
       int M=N;
       if(M%i==0)
       {
       cnt+=2;
      // cout<<i<<" "<<M/i<<" ";
      }
       
       //M=N;
   }
   
   if(i*i==N)
   {
       cnt++;
      // cout<<i<<" ";
   }
   
   
   
   
   cout<<cnt+2;
    return 0;
    
//    cout<<"Sum of x+y = " << z;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

template <class T>
inline void read(T &x)
{
    x = 0;
    int f = 0;
    char ch = getchar();
    while (!isdigit(ch))    { f |= ch == '-'; ch = getchar(); }
    while (isdigit(ch))     { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
    x = f ? -x : x;
    return;
}

int a[110];
int n;
bool flag = true;

int main()
{
    read(n);
    for (int i = 1; i <= n; ++i)
    {
        read(a[i]);
        if (a[i] % 2 == 0)
        {
            if (a[i] % 3 != 0 && a[i] % 5 != 0)
            {
                flag = false;
                break;
            }
        }
    }
    puts(flag ? "APPROVED" : "DENIED");
    return 0;
}

Measured memory_bytes: 256
<?php

$mod7 = (pow(10, 9) + 7);

$N = trim(fgets(STDIN));
$A = explode(' ', trim(fgets(STDIN)));

$cnt = [];
for ($i = 0; $i < 60; $i++) {

    $cnt[$i] = 0;
}

foreach ($A as $outerKey => $item) {

    for ($i = 0; $i < 60; $i++) {

        $cnt[$i] += $item >> $i & 1;
    }
}
$res = 0;
for ($i = 0; $i < 60; $i++) {

    $tmp = ($cnt[$i] * ($N - $cnt[$i])) % $mod7;
    $tmp2 = (1 << $i) % $mod7;
    $tmp = ($tmp * $tmp2) % $mod7;
    $res = ($res + $tmp) % $mod7;
}

echo $res . PHP_EOL;


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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;

int main() {
  int D, G;
  cin >> D >> G;
  int p[D], c[D];
  for (int i = 0; i < D; i++) cin >> p[i] >> c[i];

  int ans = INF;
  bool flag[D];
  for (int i = 0; i < (1 << D); i++) {
    int sum = 0;
    int cnt = 0;
    fill(flag, flag + D, false);
    for (int j = 0; j < D; j++) {
      if ((i >> j) & 1) {
        sum += p[j] * (100 * (j + 1)) + c[j];
        cnt += p[j];
        flag[j] = true;
      }
    }

    if (sum >= G) {
      ans = min(ans, cnt);
      continue;
    }

    for (int j = D - 1; j >= 0; j--) {
      if (!flag[j]) {
        int k;
        for (k = 0; k < p[j] && sum < G; k++) {
          sum += 100 * (j + 1);
          cnt++;
        }
        if (k == p[j]) sum += c[j];
        if (sum >= G) {
          ans = min(ans, cnt);
        }
        break;
      }
    }
  }

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


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)

from collections import deque

def main():
    k = int(input())
    lst = []
    bfs("",k,lst)
    print(lst[k-1])


def bfs(s,k,lst=[]):
    d = deque()
    for c in "0123456789":
        d.append(c)
    while d:
        if len(lst) > k:
            return
        now = d.popleft()
        if now=="0":
            continue
        lst.append(now)
        for nxt in [int(now[-1])-1,int(now[-1]),int(now[-1])+1]:
            if nxt < 0 or nxt > 9:
                continue
            d.append(now+str(nxt))









if __name__ == '__main__':
    main()


Measured memory_bytes: 24044
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a[26]={};
    string s;
    cin >> s;

    bool ok = (s[2]==s[3] && s[4]==s[5]);

    if(ok) cout << "Yes" << '\n';
    else cout << "No" << '\n';
    return 0;
}

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

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

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll h,w,a,b;
    cin >> h >> w >> a >> b;
    if(h == 1){
        for(i = 0;i < a;++i) cout << 0;
        for(i = a;i < w;++i) cout << 1;
        cout << endl;
        return 0;
    }else if(w == 1){
        for(i = 0;i < b;++i){
            cout << 0 << endl;
        }
        for(i = b;i < h;++i){
            cout << 1 << endl;
        }
        return 0;
    }
    for(i = 0;i < h;++i){
        for(j = 0;j < w;++j){
            if(i < b && j < a) cout << 0;
            else if(i >= b && j >= a) cout << 0;
            else cout << 1;
        }
        cout << endl;
    }

    return 0;
}

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

using namespace std;

int main()
{

    int N;
    cin >> N;

    vector<long> A(N);
    for(int i = 0; i < N; i++){
	cin >> A.at(i);
    }

    long sum = 0;
    for(int i = 0; i < N; i++){
	sum += (A.at(i)-1);
    }

    cout << sum << endl;
    
}


Measured memory_bytes: 256
#include <math.h>
#include <ctype.h>
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define REP(i, n) for(int i = 0; i < n; i++)
struct omt{omt(){ios::sync_with_stdio(false);cin.tie(0);}}star;

int main(){
    int w, a, b;
    cin >> w >> a >> b;
    if(a > b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    int ans = b - (a + w);
    if(ans < 0) ans = 0;
    cout << ans << endl;


    return 0;
}

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

typedef long long ll;
int main() {
  string s, t;
  cin >> s;
  cin >> t;
  string s2 = s+s;
  int n = s.size();
  vector<vector<int>> pos(n+1, vector<int>(26, -1));
  // cerr << s2 << endl;
  int inf = 3*n;
  for (int i = 0; i <= n; ++i) { 
    for (int j = 0; j < 26; ++j) { 
      if (pos[i][j] >= 0) continue;
      char c = 'a'+j;
      string::size_type p = s2.find_first_of(c, i);
      int p2;
      if (p == string::npos) p2 = inf-1;
      else p2 = p;
      for (int k = i; k <= min(p2, n); ++k) { 
        pos[k][j] = p2+1;
      }
      // cerr << c << " " << p2 << endl;
    }
  }
  int p = 0;
  int cnt = 0;
  for (char c : t) {
    int j = c-'a';
    int np = pos[p][j];
    // cerr << c << " " <<  p << " " << np << endl;
    if (np == inf) {
      cout << -1 << endl;
      return 0;
    }
    if (np >= n+1) { 
      cnt += 1;
      p = np-n;
    }
    else { p = np; }
  }
  ll ans = (ll)cnt*(ll)n+(ll)p;
  cout << ans << endl;
}


Measured memory_bytes: 13952
#include<iostream>
#include<climits>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
int main(){

	string s;
	cin >> s;
	int k;
	cin >> k;

	int n = s.size();
	vector< string > data;
	int pos = 0;
	int lim = n > k ? k : n;
	for(int i = 0; i < lim; i++)
	{
		pos = 0;
		while(pos+i+1 <= s.size()){
			data.push_back(s.substr(pos, i+1));
			pos += 1;
		}
		
	}

	sort(data.begin(), data.end());
	unique(data.begin(), data.end());
	
	cout << data[k-1] << endl;
	
	
	return 0;
}

Measured memory_bytes: 1660
#include <iostream> // c++の標準入出力
#include <stdio.h> // c言語の標準入出力
#include <string>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
	int a, b, c, d, e;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	d = a - b;
	e = c-a + b;
		if (d<c) { printf("%d", e); }
		else  { printf("%d", 0); }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
const ll mod=1e9+7;

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

ll dp[1100][1100];

int main()
{
	ll h,w,i,j;
	cin>>h>>w;
	string s[h];
	for(i=0;i<h;i++)
		cin>>s[i];
	for(i=0;i<h;i++)
		for(j=0;j<w;j++)
			dp[i][j]=0;
	dp[0][0]=1;
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(s[i][j] == '.')
			{
				if(i == 0 && j!=0)
					dp[i][j]=dp[i][j-1];
				else if(j==0 && i!=0)
					dp[i][j]=dp[i-1][j];
				else if(i==0 && j==0)
					dp[i][j]=1;
				else
					dp[i][j]=dp[i-1][j]+dp[i][j-1];
				dp[i][j]%=mod;
			}
		}
	}
	cout<<dp[h-1][w-1];
}

Measured memory_bytes: 9856
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
#include<cstdlib>
#include<typeinfo>


using namespace std;
#define INF 1000000005
int main()
{
int h,w;
std::cin >> h >> w;
std::vector<std::vector<char>> map;
std::vector<std::vector<char>> red;
std::vector<std::vector<char>> blue;
for(int i = 0; i < h; i++){
    std::vector<char> temps;
    std::vector<char> tempr;
    std::vector<char> tempb;
    for(int j = 0; j < w; j++){
        char temp;
        std::cin >> temp;
        temps.push_back(temp);
        if(temp == '#'){
            tempr.push_back('#');
            tempb.push_back('#');
        } else if(i % 2 == 0){
            if(j == 0){
                tempr.push_back('#');
                tempb.push_back('.');
            } else if(j == w - 1){
                tempb.push_back('#');
                tempr.push_back('.');
            }else {
                tempb.push_back('.');
                tempr.push_back('#');
            }
        } else {
            if(j == w - 1){
                tempb.push_back('#');
                tempr.push_back('.');
            } else if(j == 0){
                tempb.push_back('.');
                tempr.push_back('#');
            }else {
                tempr.push_back('.');
                tempb.push_back('#');
            } 
        }
    }
    map.push_back(temps);
    red.push_back(tempr);
    blue.push_back(tempb);
}
for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
        std::cout << red[i][j];
    }
    std::cout << std::endl;
}
std::cout << std::endl;
for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
        std::cout << blue[i][j];
    }
    std::cout << std::endl;
}
return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main()
{	
	int n,q,a,sum=0;
	cin>>n;
	vector<int>v(n);
	for(int i=0;i<n;i++)cin>>v[i];
	cin>>q;
	for(int i=0;i<q;i++)
	{
		cin>>a;
		if(binary_search(v.begin(),v.end(),a))sum++;
	}
	cout<<sum<<endl;
	return 0;	
}


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

using static Input;
using static Util;
class Program
{
    static int N,K;
    static int[] H;
    static void INPUT()
    {
        N = NextInt();
        K = NextInt();
        H = LineInt();
    }

    static void OUT()
    {
        var dp = new int[N];
        for (int i = 1; i < N; i++)
        {
            dp[i] = INF;
        }
        for (int i = 0; i < N - 1; i++)
        {
            for (int k = 1; k <= K && i + k < N; k++)
            {
                dp[i + k] = Math.Min(dp[i + k], dp[i] + Math.Abs(H[i] - H[i + k]));
            }
        }
        Console.WriteLine(dp[N - 1]);
    }
    static void Main(string[] args)
    {
#if DEBUG  
        //TESTINPUT();
        INPUT();

#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{

}




Measured memory_bytes: 19936
import bisect
import collections
import sys
import heapq

sys.setrecursionlimit(100000)
input = sys.stdin.readline
ACMOD = 1000000007
INF = 1 << 32


class UnionFind(object):
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def members_dict(self):
        pass

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def lmi():
    return list(map(int, input().split()))


def llmi_index(n):
    return [[i] + lmi() for i in range(n)]


N = int(input())
XY = llmi_index(N)
x_sorted = sorted(XY, key=lambda v: v[1])
y_sorted = sorted(XY, key=lambda v: v[2])
# print(x_sorted)
# # print(y_sorted)

uf = UnionFind(N)
cost_hq = []  # cost , index,index
for i in range(N - 1):
    cost = x_sorted[i + 1][1] - x_sorted[i][1]
    heapq.heappush(cost_hq, (cost, x_sorted[i][0], x_sorted[i + 1][0]))
for i in range(N - 1):
    cost = y_sorted[i + 1][2] - y_sorted[i][2]
    heapq.heappush(cost_hq, (cost, y_sorted[i][0], y_sorted[i + 1][0]))

ans = 0
while cost_hq:
    cost, index1, index2 = heapq.heappop(cost_hq)
    # print(cost, index1, index2)
    if uf.same(index1, index2):
        continue
    # print('join {},{}'.format(index1,index2))
    uf.union(index1, index2)
    ans += cost

print(ans)


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

#define EPS (1e-7)
#define INF (1<<25)
#define PI (acos(-1))

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

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

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

using ll = long long;

int main() {
  int n, k; cin >> n >> k;
  vector<int> d(k); REP(i,k) cin >> d[i];

  vector<int> a(7);
  FOR(x,n,10*n+1) {
    REP(i,7) a[i] = 0;
    int cnt = 0;
    int t = x;
    while(t) {
      a[cnt++] = t%10;
      t/=10;
    }
    bool f = true;
    REP(i,cnt) REP(j,k) if (a[i] == d[j]) f = false;
    if (f) { cout << x << endl; return 0; }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n;
    int ans=0;
    string s;
    cin>>n>>s;
    for(int i=1;i<s.size();i++){
        map<char,int> P;
        int p=0;
        for(int j=0;j<i;j++){
            char a=s[j];
            P[a]=1;
        }
        for(int k=i;k<s.size();k++){
            char b=s[k];
            if(P[b]==1){
                p++;
                P[b]=0;
            }
        }
        ans=max(ans,p);
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 256
N,M,*A = `dd`.split.map &:to_i
dp = {}
dp[0] = 1
s = 0
ans = 0
A.each{ |a|
  s = (s + a) % M
  ans += (dp[s] || 0)
  dp[s] = (dp[s] || 0) + 1
}
p ans

Measured memory_bytes: 13056
#include "bits/stdc++.h"

const int INF = 1e9;

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);

    int h, w, m;
    std::cin >> h >> w >> m;

    std::map<int, int> cntx, cnty;
    std::map<int, std::map<int, int>> cnt;

    for (int i = 0, x, y; i < m; i++) {
        std::cin >> x >> y;
        cntx[x]++;
        cnty[y]++;
        cnt[x][y]++;
    }

    int ans = 0;
    int xmax = 0, ymax = 0, vmax;

    // FOR X:
    vmax = 0;
    for (auto &[x, c] : cntx) {
        if (c > vmax) {
            vmax = c;
            xmax = x;
        }
    }

    std::vector<int> y;
    for (auto &[p, c] : cnty)
        y.push_back(c - cnt[xmax][p]);
    std::sort(y.begin(), y.end());

    ans = vmax + y.back();

    // FOR Y:
    vmax = 0;
    for (auto &[y, c] : cnty) {
        if (c > vmax) {
            vmax = c;
            ymax = y;
        }
    }

    std::vector<int> x;
    for (auto &[p, c] : cntx)
        x.push_back(c - cnt[p][ymax]);
    std::sort(x.begin(), x.end());

    ans = std::max(ans, vmax + x.back());

    std::cout << ans;
}

Measured memory_bytes: 103836
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        double ans = 1;
        for (int i=1; i<=n; i++) {
            double pwr = Math.pow(2, i);
            if (pwr > n) {
                System.out.println((int) ans);
                return;
            }
            ans = pwr;
        }
   }
}


Measured memory_bytes: 20820
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define pb push_back
#define all(in) in.begin(),in.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

const int MOD = 1e9+7;
const int MAX = 2e6;

// a^n mod.p を計算する（二分累乗法）ただしpは素数
long long modpow(long long a, long long n, long long p) {
    long long res = 1;
    while (n) {
        if (n & 1) res = res * a % p;
        a = a * a % p;
        n >>= 1;
    }
    return res;
}

// nCk mod.MOD を求める方法1　ただしpは素数 p > n
// p = (p/a) * a + (a%b) を変形すると a^(-1) = -(p%a)^(-1) * (p/a)
long long fac[MAX], finv[MAX], inv[MAX];
// 前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1; // mod.MODにおける1,2,…,nの逆元
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD; // iの逆元をMOD/iの逆元を利用して求める
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数の計算
long long COM(int n, int k){
    if (n < 0 || k < 0 || n < k) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    int n; cin >> n;
    string s; cin >> s;
    int k = s.length();
    
    ll ans = 0;
    COMinit();

    for(int i=k; i<=n+k; i++){ // (i-1 C k-1) * (25^(i-k)) * (26^(n+k-i)) を数え上げる
        ll num = ((COM(i-1, k-1) % MOD) * modpow(25, i-k, MOD) % MOD) * modpow(26, n+k-i, MOD) % MOD;
        ans += num;
        ans %= MOD;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 51228
#include<bits/stdc++.h>
typedef long long ll;
const ll mod=1e9+7;
using namespace std;
vector<pair<int,int>> v[100005];
int in[100005];
int ans[100005];
void dfs(int u,int fa,int c,int mx)
{
    for(int i=0;i<v[u].size();i++)
    {
        int j=v[u][i].first;
        if(j==fa) continue;
        ans[v[u][i].second]=c;
        c=(c+1)%mx;
        dfs(j,u,c,mx);
    }
}
int main()
{
    int n;cin>>n;
    for(int i=1;i<=n-1;i++)
    {
        int a,b;
        cin>>a>>b;
        v[a].push_back({b,i});
        v[b].push_back({a,i});
        in[a]++;in[b]++;
    }
    int root=0,mx=0;
    for(int i=1;i<=n-1;i++)
    {
        if(in[i]>mx)
        {
            root=i;
            mx=in[i];
        }
    }
    dfs(root,-1,0,mx);
    cout<<mx<<endl;
    for(int i=1;i<=n-1;i++)
        cout<<ans[i]+1<<endl;
    return 0;
}


Measured memory_bytes: 11828
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  string s;
  cin >> s;
  deque<char> dq;
  rep(i, s.size()){
    dq.push_back(s.at(i));
  }
  bool f = false;
  int q;
  cin >> q;
  rep(_q, q){
    int in;
    cin >> in;
    if(in == 1){
      f ^= 1;
    }else{
      int tr;
      char c;
      bool t;
      cin >> tr >> c;
      if(tr == 2) t = true;
      else t = false;
      // cerr << t << f << c << endl;
      if(f^t == true) dq.push_back(c);
      else dq.push_front(c);
    }
  }
  while(!dq.empty()){
    char c;
    if(f == false){
      c = dq.front();
      dq.pop_front();
    }else{
      c = dq.back();
      dq.pop_back();
    }
    cout << c;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#define endl enjoy_codeforces
int main(){
    std::map<int,int>map;
    int n;std::cin>>n;
    while(n--){
        int x;std::cin>>x;
        map[x]++;
    }
    std::cin>>n;
    while(n--){
        int x;std::cin>>x;
        map[x]--;
    }
    for(auto&&p:map){
        if(p.second<0){
            std::cout<<"NO"<<'\n';
            return 0;
        }
    }
    std::cout<<"YES"<<'\n';
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;

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

Measured memory_bytes: 3632
def main():
    n = int(input())
    nums = list(map(int, input().split()))
    for i in range(n-1, -1, -1):
        if i == 0:
            print(nums[i])
        else:
            print(f"{nums[i]} ", end="")
    return 0


if __name__ == "__main__":
    main()



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

Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

int dp[101][100001]; // i番目まで配って残りj個になる場合の数

signed main() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    dp[0][K] = 1;
    for (int i = 0; i < N; i++) {
        vector<int> S(K + 2, 0);
        for (int j = 0; j <= K; j++) (S[j+1] = S[j] + dp[i][j]) %= MOD;
        for (int j = 0; j <= K; j++) (dp[i+1][j] = S[min(j+1 + A[i], K + 1)] - S[j] + MOD) %= MOD;
    }
    cout << dp[N][0] << endl;
}

Measured memory_bytes: 79216
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,min_v=1000000000,max_v=0,a;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a);
		min_v=min(min_v,a);
		max_v=max(max_v,a);
	}
	printf("%d",max_v-min_v);
	return 0;
}

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

int main()
{
  int a;
  cin>>a;
  if(a%2==0)
  {  
     a=a/2;
  }
  else
  {
    a=(a/2)+1;
  }
   cout<<a<<"\n" ;
   return 0;
  }

Measured memory_bytes: 256
// ------------------------------------
// Date:2018/ 2/28
// Problem:ABC 063 Bugged c.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;
const int MAX_N = 101;
const int MAX_SUM = 10101;

bool dp[MAX_N][MAX_SUM];

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N;
  cin >> N;
  vector< int > s(N);
  REP(i, N) cin >> s[i];
  memset(dp, false, sizeof(dp));

  dp[0][0] = true;
  REP(i, N) {
    REP(j, MAX_SUM + 1) {
      dp[i + 1][j] |= dp[i][j];
      if (j >= s[i]) dp[i + 1][j] |= dp[i][j - s[i]];
    }
  }


  int ans = 0;
  RREP(i, MAX_SUM) {
    if (i % 10 == 0) continue;
    if (dp[N][i]) {
      ans = i;
      break;
    }
  }
    
  cout << ans << endl;
  return 0;
}



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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

int main() {
    int y, m, d;
    scanf("%d/%d/%d", &y, &m, &d);

    cout << (y <= 2019 && m <= 4 && d <= 30 ? "Heisei" : "TBD") << endl;

    return 0;
}


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

int main() {
  long long x;
  cin >> x;
  
  long long money = 100;
  long long cnt = 0;
  
  while(1){
    cnt++;
    money *= 1.01;
    if(money >= x){
      cout << cnt << endl;
      break;
    }
  }
  
}




Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int main()
{
	int a, b;

	cin >> a >> b;

	if ((a + b) % 2 == 0) {


		cout << (a + b) / 2 << endl;
	}
	else {
		cout << "IMPOSSIBLE" << endl;

	}

	return 0;





}


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

#define LEN(x) (strlen(x))
int main(){
  int n, i, j, fp, sp, ans[100], carry;
  char f[1000], s[1000];
  scanf("%d", &n);
  while(n--){
    scanf("%s%s", f, s);
    if(LEN(f) > 80 || LEN(s) > 80){
      puts("overflow");
      continue;
    }
    fp = LEN(f);
    sp = LEN(s);
    j = carry = 0;
    while(fp || sp){
      ans[j] = carry;
      if(fp) ans[j] += f[--fp] - '0';
      if(sp) ans[j] += s[--sp] - '0';
      carry = ans[j] / 10;
      ans[j++] %= 10;
    }
    if(carry) ans[j] = 1;
    else j--;
    if(j >= 80){
      puts("overflow");
      continue;
    }

    for(;j >= 0;j--)
      printf("%d", ans[j]);
    puts("");
  }
  return 0;
}

Measured memory_bytes: 608
def multiplyList(myList) : 
      
    # Multiply elements one by one 
    result = 1
    for x in myList: 
        result = result * x
        if result == 0:
             return 0 
        if result > 10**18:
             return -1
    return result
 
n = int(input())
l = list(map(int, input().split()))
l.sort()
res = multiplyList(l)
print(res)

Measured memory_bytes: 21792
#include <iostream>

using namespace std;

int sl, tl;          // 字符串长度
int similarity;      // 两个字符串的相似度
string s, t;

int ans;

int main() {
  cin >> s >> t;
  sl = s.size(), tl = t.size();
  for (int i = 0; i <= sl - tl; i++) {
    similarity = 0;
    for (int j = 0; j < tl; j++) {
      similarity += s[i + j] == t[j];
    }
    ans = max(ans, similarity);
  }
  cout << tl - ans;
  return 0;
}

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

using namespace std;

int main(void) {
	int h, w;
	cin >> h >> w;
	vector<vector<string>>s(h, vector<string>(w));
	char alpha[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	char ans;
	int ans_;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> s[i][j];
			if (s[i][j] == "snuke") {
				ans = alpha[j];
				ans_ = i+1;
			}
		}
	}
	cout << ans << ans_;
	return 0;
}

Measured memory_bytes: 768
s = input()
a, b, c, d = s[0], s[1], s[2], s[3]
for op1 in "+-":
  for op2 in "+-":
    for op3 in "+-":
      f = a+op1+b+op2+c+op3+d
      if eval(f)==7:
        print(f+"=7")
        exit()

Measured memory_bytes: 3060