akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

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

int main() {
	IOS();
	ll a, b, t;
	cin >> a >> b >> t;
	dump(t / a * b);
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<queue>
#include<stack>
#include<ctime>
using namespace std;
#define yes printf("YES")
#define no printf("NO")
int a,b,c;
signed main(){
	cin>>a>>b>>c;
	if(a==1){
		yes;
		return 0;
	}
	int i;
	for(i=1;i<=b;i++){
		if((a*i)%b==c){
			yes;
			return 0;
		}
	}
	no;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
typedef priority_queue<ll> PQ_HIGH;
typedef priority_queue<ll,VL,greater<ll>> PQ_LOW;//昇順

int main(){
  int s,w;cin>>s>>w;
  if(s<=w){
    cout<<"unsafe"<<endl;
  }else{
    cout<<"safe"<<endl;
  }
}

Measured memory_bytes: 3592
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Main main = new Main();
        main.solve();
    }
    public void solve() throws Exception {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int A = scan.nextInt();
        int B = scan.nextInt();
        int C = scan.nextInt();
        int ans = Math.max(0, C - (A-B));
        System.out.println(ans);
    }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    int n,a;
    cin>>n>>a;
    n%=500;
    if(n<=a) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
import math as mt
import collections as cc
I=lambda:list(map(int,input().split()))
ans=[]
prev=0
for i in range(1,15):
    ans.append(26**i+prev)
    prev+=26**i
    
n,=I()
p=0
s='abcdefghijklmnopqrstuvwxyz'
f={}
for i in range(1,27):
    f[i]=s[i-1]
for i in range(len(ans)):
    p+=1
    if n<=ans[i]:
        break
an=''
f[0]='z'
for i in range(p):

    an+=f[n%26]
    if n%26:
        n//=26
    else:
        n//=26
        n-=1
    
print(an[::-1])
    

Measured memory_bytes: 65328
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;

int m,n;
char talk[1024],num[200];

int main(){
	int i;
	while( cin >> m >> n ){
		int kill[1000] = {0};
		int surcnt = m;
		int man = 0;
		if( m == 0 && n == 0 )
			break;
		for( i = 1;i <= n;i++ ){

			cin >> talk;
			if( surcnt == 1 )
				continue;
			if( i % 15 == 0 )
				strcpy( num,"FizzBuzz" );
			else if( i % 5 == 0 )
				strcpy( num,"Buzz" );
			else if( i % 3 == 0 )
				strcpy( num,"Fizz" );
			else
				sprintf( num,"%d",i );
			if( strcmp( talk,num ) != 0 ){
				kill[ man ] = 1;
				surcnt--;
			}
			if( surcnt == 1 )
				continue;
			do{
				man++;
				man %= m;
			}while( kill[ man ] );
		}

		int maxsur;
		for( i = m-1;i >= 0;i-- ){
			if( kill[i] == 0 ){
				maxsur = i;
				break;
			}
		}
		for( i = 0;i <= maxsur;i++ ){
			if( kill[i] == 0 ){
				cout << i+1;
				if( i < maxsur ){
					cout << " ";
				}
				else{
					cout << endl;
				}
			}
		}
	}
	return 0;
}

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

#define UPPER_BOUND 100000
#define UPPER_BOUND_INDEX 12
#define POW_BOUND 7+1

typedef enum { false, true } bool;

int change[UPPER_BOUND_INDEX];

int min = 100000;

void change_array(void)
{
    int i, index6, index9, pow6[POW_BOUND], pow9[POW_BOUND];
    
    
    index6 = index9 = 0;
    
    
    for(i=0; i<POW_BOUND; i++)
    {
        pow6[i] = pow(6, i);
        pow9[i] = pow(9, i);
    }
    
    for(i=0; pow6[index6]<=UPPER_BOUND || pow9[index9]<=UPPER_BOUND; i++)
    {
        if(pow6[index6] < pow9[index9])
        {
            change[i] = pow6[index6];
            
            index6++;
                
            continue;
        }
        if(pow6[index6] > pow9[index9])
        {
            change[i] = pow9[index9];
            
            index9++;
            
            continue;
        }
        if(pow6[index6] == pow9[index9])
        {
            change[i] = pow6[index6];
            
            index6++;
            index9++;
            
            continue;
        }
    }
    /*for(i=0; i<UPPER_BOUND_INDEX; i++)
    {
        printf("%d\n", change[i]);
    }*/
}

int change_index(int N)
{
    int i;
    
    
    for(i=UPPER_BOUND_INDEX-1; i>=0; i--)
    {
        if(change[i] <= N)
            break;;
    }
    
    return i;
}

bool DIV(int R, int index, int num)
{
    int i;
    
    
    if(num >= min)
    {
        return false;
    }
    else if(index == 0)
    {
        if(min > num + R)
            min = num + R;
            
        return true;
    }
    else
    {
        if(R >= change[index])
        {
            for(i=R/change[index]; i>=0; i--)
            {
                if(!DIV(R-change[index]*i, index-1, num+i))
                {
                    return true;
                }
            }
        }
        else
        {
            if(!DIV(R, index-1, num))
            {
                return true;
            }
        }
    }
}

int main(void)
{
    int N;
  
  
    scanf("%d", &N);


    change_array();

    DIV(N, change_index(N), 0);


    printf("%d\n", min);


    //system("pause");
    return 0;
}


Measured memory_bytes: 128
def chmin(a,b):
    if a>b: a = b
    return a
def chmax(a,b):
    if a<b: a = b
    return a
N = int(input())
h = list(map(int,input().rstrip().split(' ')))
dp = [float('INF')]*N
dp[0] = 0
for i in range(1,N):
    dp[i] = chmin(dp[i],dp[i-1]+abs(h[i]-h[i-1]))#1個前から移動
    if i>1 : dp[i] = chmin(dp[i],dp[i-2]+abs(h[i]-h[i-2]))#2個前から移動
print(dp[-1])

Measured memory_bytes: 20636
n = int(input())
li = [input() for i in range(n)]
ans = [51]*26 #a~z
s = ""

for word in li:
    for i in range(26):
        if word.count(chr(i+97)) < ans[i]:
            ans[i] = word.count(chr(i+97))

for i in range(26):
    s += chr(i+97)*ans[i]      

print(s)

Measured memory_bytes: 3060
from collections import deque

"""
ダイクストラ　ギリギリ
"""
h, w = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
ch-=1; cw-=1; dh-=1; dw-=1
area = [list(input()) for _ in range(h)]
inf = 10**100
dist = [[inf]*w for i in range(h)]

dwalk = [(0, 1), (0, -1), (1, 0), (-1, 0)]

def Dijkstra(ch, cw):
    import heapq
    edgelist = [(0, ch, cw)]
    heapq.heapify(edgelist)
    dist[ch][cw] = 0
    while len(edgelist):
        cost, y, x = heapq.heappop(edgelist)
        if y==dh and x==dw:
            return dist
        # この枝刈がないと通らない
        if dist[y][x] < cost: continue
        for next_y, next_x in dwalk:
            if 0<=y+next_y<h and 0<=x+next_x<w:
                if area[y+next_y][x+next_x]=='#': continue
                if dist[y+next_y][x+next_x]>cost:
                    dist[y+next_y][x+next_x] = cost
                    heapq.heappush(edgelist, (cost, y+next_y, x+next_x))
        for next_y in range(-2, 3):
            for next_x in range(-2, 3):
                    if 0<=y+next_y<h and 0<=x+next_x<w:
                        if area[y+next_y][x+next_x]=='#': continue
                        if dist[y+next_y][x+next_x]>cost+1:
                            dist[y+next_y][x+next_x] = cost+1
                            heapq.heappush(edgelist, (cost+1, y+next_y, x+next_x))
    return dist

dist = Dijkstra(ch, cw)
if dist[dh][dw] == inf:
    print(-1)
else:
    print(dist[dh][dw])

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

i = 1
ans = 1
if x <= 4:
    ans = 1
else:
    i = 2
    while i <= x:
        j = 2
        while i**j <= x:
            if ans < i**j:
                ans = i**j
            j = j+1
        i = i+1

print(ans)


Measured memory_bytes: 2940
/*
 * WelcomeToAtCoder.cpp
 *
 *  Created on: 2020/02/19
 *      Author: black
 */

#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstring>
#include <stdio.h>
using namespace std;

#define M 1046527
#define L 14

char H[M][L];

// 数値から文字列への変換
int getChar(char ch){
	switch(ch){
	case 'A':
		return 1;
	case 'C':
		return 2;
	case 'G':
		return 3;
	case 'T':
		return 4;
	default:
		return 0;
	}
}

long long getStr(char str[]){
	long long sum = 0;
	int p = 1;
	for(int i=0; i<strlen(str); ++i){
		sum += p*getChar(str[i]);
		p *= 5;
	}
	return sum;
}

int h1(int key){
	return key % M;
}

int h2(int key){
	return 1+ (key % (M - 1));
}

int find(char str[]){
	long long key, i, h;
	key = getStr(str);
	for(i=0;;++i){
		h = (h1(key)+i*h2(key))%M;
		if (strcmp(H[h], str) == 0){
			return 1;
		}
		else if (strlen(H[h]) == 0){
			return 0;
		}
	}
	return 0;
}

int insert(char str[]){
	long long key, i, h;
	key = getStr(str);
	for(i=0;;++i){
		h = (h1(key)+i*h2(key))%M;
		if (strcmp(H[h], str) == 0){
			return 0;
		}
		else if (strlen(H[h]) == 0){
			strcpy(H[h], str);
			return 0;
		}
	}
	return 0;
}

int main(){
	int n;
	scanf("%d", &n);
	char com[9], str[L];

	for(int i=0; i<M; ++i){
		H[i][0] = '\0';
	}

	for(int i=0; i<n; ++i){
		scanf("%s %s", com, str);

		if (com[0] == 'i'){
			insert(str);
		}
		else{
			if(find(str)){
				cout << "yes" << endl;
			}
			else{
				cout << "no" << endl;
			}
		}
	}

	return 0;
}



Measured memory_bytes: 17536
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        m: usize,
        ps: [(usize, chars); m],
    }
    // let A = vec!['A', 'C'];
    // let W = vec!['W', 'A'];
    let mut cor = vec![0;n];
    let mut pena = vec![0;n];
    let mut flag = vec![false;n];
    for i in 0..m {
        let ind = ps[i].0;
        if ps[i].1[0]=='A' {
            // AC
            if cor[ind-1] !=1  {
                cor[ind-1]=1;
                flag[ind-1] = true;
            }
        }
        if ps[i].1[0]=='W'{
            // WA
            if flag[ind-1] == false {
                pena[ind-1]+=1;
            }
        }
    }
    for i in 0..n {
        if flag[i] == false {
            pena[i] = 0;
        }
    }
    let mut ans = 0;
    let mut penal = 0;
    for i in 0..n {
        ans+= cor[i];
        penal+= pena[i];
    }
    println!("{} {}", ans, penal);
}

Measured memory_bytes: 8444
// 21:14 - 21:26 WA

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

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

using namespace std;

int main(){
  int n;
  int a[1000005];
  int sum = 0;

  cin >> n;
  a[0] = 0;
  for(int i = 1; i <= n; i++){
    cin >> a[i];
  }
  a[n+1] = 0;
  for(int i = 0; i < n + 2; i++){
    sum += abs(a[i] - a[i-1]);
  }

  // debug
  //cout << sum << endl;

  for(int i = 1; i < n + 1; i++){
    int work = sum;
    work -= abs(a[i] - a[i-1]);
    work -= abs(a[i+1] - a[i]);
    work += abs(a[i+1] - a[i-1]);
    cout << work - n << endl;
  }

  return 0;
}


Measured memory_bytes: 3584
package main

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

func Search(n int, cond func(i int) bool) int {
	for m := -1; (n - m) > 1; {
		i := int(m + (n-m)/2)
		if cond(i) {
			n = i
		} else {
			m = i
		}
	}
	return n
}

func Solve(in io.Reader, out io.Writer) {
	var n int
	var as, bs, cs []int

	scanner := bufio.NewScanner(in)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	n, _ = strconv.Atoi(scanner.Text())

	as = make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		as[i], _ = strconv.Atoi(scanner.Text())
	}
	bs = make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		bs[i], _ = strconv.Atoi(scanner.Text())
	}
	cs = make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		cs[i], _ = strconv.Atoi(scanner.Text())
	}

	ret := 0
	sort.Ints(as)
	sort.Sort(sort.Reverse(sort.IntSlice(cs)))
	for _, b := range bs {
		c1 := Search(n, func(i int) bool { return as[i] >= b })
		c2 := Search(n, func(i int) bool { return cs[i] <= b })
		ret += c1 * c2
	}
	fmt.Fprintln(out, ret)
}

func main() {
	Solve(os.Stdin, os.Stdout)
}


Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

void solve() {
  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  string S;
  cin >> S;
  vector<ll> B;
  set<ll> se;
  se.insert(0);
  rrep(i, N) {
    ll a = A[i];
    for(ll b: B) a = min(a^b, a);
    if(S[i] == '0') {
      B.emplace_back(a);
    } else {
      if(a != 0) {
        cout << 1 << endl;
        return;
      }
    }
  }
  cout << 0 << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int T;
  cin >> T;
  rep(t, T) solve();
  return 0;
}


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

int main()
{
    ll A, B;
    cin >> A >> B;
    cout << max(max(A + B, A - B), A * B) << endl;
    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
m=1000
day_buy=[]
for i in range(n):
    if i==0:
        if a[i]<a[i+1]:
            day_buy.append(i)
    elif i<n-1:
        if a[i-1]>=a[i] and a[i]<a[i+1]:
            day_buy.append(i)
day_sell=[]
for j in range(n):
    if n-1>j>0:
        if a[j-1]<a[j] and a[j]>=a[j+1]:
            day_sell.append(j)
    elif j==n-1>0:
        if a[j-1]<a[j]:
            day_sell.append(j)
k=0
for i in range(len(day_buy)):
    kb=m//a[day_buy[i]]
    m-=kb*a[day_buy[i]]
    k+=kb
    m+=k*a[day_sell[i]]
    k=0
print(m)


Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

ll ctoi(char c){
    switch (c){
        case '0': return 0;
        case '1': return 1;
        case '2': return 2;
        case '3': return 3;
        case '4': return 4;
        case '5': return 5;
        case '6': return 6;
        case '7': return 7;
        case '8': return 8;
        case '9': return 9;
        default: return 0;
    }
}

int main(){
    ll N;
    cin >> N;
    ll P;
    cin >> P;
    string S;
    cin >> S;
    vector<ll> count(P, 0);
    ll now = 0;
    ll num = 1;
    count[0]++;
    if (P == 2){
        ll ans = 0;
        rep(i,N){
            if (ctoi(S[i]) % 2 == 0) ans += (i + 1);
        }
        cout << ans << endl;
    }
    else if (P == 5){
        ll ans = 0;
        rep(i,N){
            if (ctoi(S[i]) % 5 == 0) ans += (i + 1);
        }
        cout << ans << endl;
    }
    else{
        rep(i, N){
            now = (now + num * ctoi(S[N - i - 1])) % P;
            count[now]++;
            num = (num * 10) % P;
        }
        ll ans = 0;
        rep(i, P){
            ans += count[i] * (count[i] - 1) / 2;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
#include <chrono>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9
#define f first
#define s second

typedef long long ll;

using namespace std;

int main()

{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int l, r, ans = INT_MAX;

    cin >> l >> r;

    if ((l-1)/2019 != r/2019) {

        cout << "0";
        return 0;
    }

    for (int i = l; i < r; i++) {

        for (int j = i+1; j <= r; j++) {

            int z = ((i%2019)*(j%2019))%2019;
            ans = min(ans, z);
        }
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;
const int maxn = 50 * 100 + 20;
LL dp[maxn];
void work() {
    int n, p;
    cin >> n >> p;
    dp[0] = 1;
    for (int i = 1; i <= n; ++i) {
        int val;
        cin >> val;
        for (int j = maxn - 20; j >= val; --j) {
            dp[j] += dp[j - val];
        }
    }
    LL ans = 0;
    for (int i = 0; i <= maxn - 20; ++i) {
        if (i % 2 == p) {
            ans += dp[i];
        }
    }
    cout << ans << endl;
}

int main() {
#ifdef local
    freopen("data.txt", "r", stdin);
//    freopen("data.txt", "w", stdout);
#endif
    work();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

struct bit {
    vector<ll> v; // 部分和をbitで管理 仮想配列はa[1...n]
    bit(int n){ // bit(int n) : v(n + 1) {}
        v.resize(n + 1);
    }
    
    ll sum(int i){ // 仮想配列a[1]~a[i]の和を求める
        ll ret = 0;
        for(; i > 0; i -= i & -i){ // i & -i: iの1が立っている最高位bitをの2^を返す
            ret += v[i];
        }
        return ret;
    }
    
    void add(int i, ll w) { // index:iにwを加える
        for (; i < v.size(); i += i & -i) {
            v[i] += w;
        }
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    string s;
    cin >> s;
    int N = (int)s.size();
    vector<vector<int>> A(26);
    rep(i, s.size()){
        A[s[i] - 'a'].pb(i);
    }
    
    int odds = 0;
    int odd_ind = -1;
    rep(i, 26){
        if(A[i].size() % 2 == 1) {
            odds++;
            odd_ind = i;
        }
    }
    
    if(s.size() % 2 == 0 && odds > 0){
        output(-1);
        return 0;
    }
    if(s.size() % 2 == 1 && odds != 1){
        output(-1);
        return 0;
    }
    
    vector<ll> Q(N);
    if(s.size() % 2 == 1){
        int center = A[odd_ind][A[odd_ind].size() / 2];
//        ans = abs(N / 2 - center);
        Q[N / 2] = center + 1;
    }
    
    
    
    
    vector<pair<ll, ll>> P;
    rep(i, 26){
        rep(j, A[i].size() / 2){
            P.pb({A[i][j], A[i][A[i].size() - 1 - j]});
        }
    }
    
    sort(all(P), [](const pair<ll, ll> &a, const pair<ll, ll> &b){
        return b.first - a.first + a.second - b.second > 0;
    });
//
//    rep(i, P.size()){
//        ans += abs(P[i].first - i) + abs(P[i].second - (N - 1 - i));
//    }
//
    
    
    rep(i, P.size()){
        Q[i] = P[i].first + 1;
        Q[N - 1 - i] = P[i].second + 1;
    }
    
    
    bit B(N);
    
    ll ans = 0;
    rep(i, N){
        ans += i - B.sum(Q[i]);
        B.add(Q[i], 1);
    }
    output(ans);
    
    return 0;
}


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

long long N, A[17][17], R[1 << 17], dp[1 << 17];

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) cin >> A[i][j];
	}
	for (int i = 0; i < (1 << N); i++) {
		int bit[17]; for (int j = 0; j < N; j++) bit[j] = (i / (1 << j)) % 2;
		for (int j = 0; j < N; j++) {
			for (int k = 0; k < N; k++) {
				if (bit[j] == 1 && bit[k] == 1) R[i] += A[j][k];
			}
		}
	}
	for (int i = 0; i < (1 << N); i++) {
		vector<int>vec; for (int j = 0; j < N; j++) { if ((i / (1 << j)) % 2 == 0) vec.push_back(j); }

		int t = 0;
		for (int j = 0; j < (1 << vec.size()); j++) {
			dp[i + t] = max(dp[i + t], dp[i] + R[t]);

			int s = j, cnt = 0;
			while ((s & 1) == 1) { t -= (1 << vec[cnt]); s >>= 1; cnt++; }
			if (cnt != vec.size()) t += (1 << vec[cnt]);
		}
	}
	cout << dp[(1 << N) - 1] / 2 << endl;
	return 0;
}

Measured memory_bytes: 1280
program key2020_D
    implicit none
    integer::N
    integer,allocatable,dimension(:)::A,B,T
    integer,allocatable,dimension(:,:)::DP
    integer::M,ans, siz1,siz2
    integer::i,j,S,k,x,y
    read*,n;m=2**n
    allocate(A(0:N-1),B(0:N-1),DP(0:M,0:N),T(0:N))
    read*,A(0:N-1)
    read*,B(0:N-1)
    T(0)=m-1
    do i=0,N-1
        T(i+1)=xor(T(i),2**i)
    end do
    do S=0,m-1
        do k=0,n-1
            dp(S,k)=10**9
        end do
    end do
    do k=0,N-1
        dp(2**k,k)=k
    end do
    
    do S=0,M-1
        siz1=0
        do i=0,n-1
            if (and(S,2**i)/=0)siz1=siz1+1
        end do
        do x=0,N-1
            siz2=0
            if (and(S,2**x)==0)cycle
            do i=0,N-1
                if (and(and(S,T(x+1)),2**i)/=0) siz2=siz2+1
            end do
            do y=0,N-1
                if (x==y.or.(and(S,2**y)==0))cycle
                if (f(y,siz1)<=f(x,siz1-1)) dp(S,x)=min(dp(S,x),dp(xor(S,2**x),y)+x+1-siz1+siz2)
            end do
        end do
    end do

    ans=10**5
    do i=0,N-1
        ans=min(ans,dp(m-1,i))        
    end do
    
    print"(I0)",merge(-1,ANS,ANS==10**5)
contains
integer function f(x,d)
    integer ::x,d
    f=merge(A(x),B(x),mod(X-d,2)==0)
end function
end program key2020_D

Measured memory_bytes: 19584
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int getMaxPoint(int n, vector <int>& a, vector <int>& b, vector <int>& c) {
	vector <vector <int>> dp(n + 1, vector <int>(3, 0));
	int cur = 0;
	for (int  i = 1; i <= n; ++i) {
		for (int j = 0; j < 3; ++j) {
			cur = (j == 0) ? a[i - 1] : 
			(j == 1 ? b[i - 1] : c[i - 1]);
			dp[i][j] = max(dp[i][j], max(cur + dp[i - 1][(j + 1)%3], 
			cur + dp[i - 1][(j + 2)%3]));
		}
	}
	return max(dp[n][0], max(dp[n][1], dp[n][2]));
}


int main() {
	int n, A, B, C;
  	cin >> n;
  	vector <int> a, b, c;
  	for(int i = 0; i < n; ++i) 
      cin >> A >> B >> C, a.push_back(A), b.push_back(B), c.push_back(C);
  	cout << getMaxPoint(n, a, b, c) << endl;
}



Measured memory_bytes: 6892
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        PriorityQueue<Integer> pq = new PriorityQueue<>();
        for (int i = 0; i < n; i++) {
            pq.add(Integer.parseInt(sc.next()));
        }
        sc.close();

        // 主処理
        int result = 0;
        for (int i = 0; i < k; i++) {
            result += pq.poll();
        }

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 38436
#include <bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define x             first
#define y             second
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define PI            3.14159265358979
#define N             200005

int solve(){
    string s,t; cin>>s>>t;
    int n=s.size(),m=t.size();
    int dp[n+1][m+1]={};
    dp[0][0]=0;
    for (int i = 0; i <= n; ++i)
    {
        for(int j=0; j<=m; j++){
            if(i==0&&j==0) continue;
            if(s[i-1]==t[j-1])
                dp[i][j]=dp[i-1][j-1]+1;
            else{
                if(i>0)
                    dp[i][j]=max(dp[i][j],dp[i-1][j]);
                if(j>0)
                    dp[i][j]=max(dp[i][j],dp[i][j-1]);
            }
        }
    }
    int i=n,j=m;
    string ans="";
    while(i&&j){
        if(s[i-1]==t[j-1]){
            ans+=s[i-1];
            i--; j--;
        }
        else if(dp[i][j]==dp[i-1][j]+1){
            j--;
        }
        else{
            i--;
        }
    }
    reverse(ans.begin(), ans.end());
    cout<<ans;
    return 0;
}

signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 73944
#include <bits/stdc++.h>
using namespace std;
int main() {
    int H, W, N;
    cin >> H >> W >> N;
    vector<int> A;
    for(int i = 1; i <= N; i++) {
        int a; cin >> a;
        for(int j = 0; j < a; j++) A.push_back(i);
    }
    
    vector<vector<int>> C(H, vector<int>(W));
    int x = 1;
    int y = 0;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            if(x==1) C.at(i).at(j) = A.at(y);
            else C.at(i).at(W-1-j) = A.at(y);
            y++;
        }
        x = 1 - x;
    }
    
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            cout << C.at(i).at(j);
            if(j!=W-1) cout << " ";
            else cout << endl;
        }
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

//約数列挙O(root n)
vector<PLL> divisor(ll n){
  vector<PLL> v;
  for(int i=1; i<=sqrt(n); i++){
    if(n%i == 0){
      v.push_back(PLL(i,n/i));
    }
  }
  return v;
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  ll N;cin >> N;
  vector<PLL> div = divisor(N);
  ll MI = MAX_LL;
  for(const PLL & p : div){
    MI = min(MI,p.first+p.second-2);
  }
  cout << MI << endl;
  return 0;
}


Measured memory_bytes: 384
# 全方位DP
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
from collections import defaultdict, deque
from math import factorial

MOD = 10**9+7
class Facts():
    def __init__(self, max_num=10**5, p=10**9 + 7):
        self.p = p
        self.max_num = max_num
        self.fact = [1] * (self.max_num + 1)
        for i in range(1, self.max_num + 1):
            self.fact[i] = self.fact[i-1] * i
            self.fact[i] %= self.p

    def power_func(self, a, b):
        ans = 1
        while b > 0:
            if b & 1:
                ans = ans * a % self.p
            a = a * a % self.p
            b >>= 1
        return ans

    def fact_inv(self, a):
        return self.power_func(a, self.p-2) % self.p

n = int(input())
fact = Facts(max_num=200000)
edges = defaultdict(lambda: [])

for _ in range(n-1):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)

# step1 吸い上げ
size = [1 for _ in range(n+1)]
def dfs1(num, par=-1):
    res = 1
    for node in edges[num]:
        if node == par:
            continue
        else:
            res += dfs1(node, num)
    res %= MOD
    size[num] = res
    return res
dfs1(1)
# print(size)
dp = [0 for _ in range(n+1)]
def dfs2(n, par=-1):
    res = fact.fact[size[n] - 1]
    for node in edges[n]:
        if node == par:
            continue
        else:
            res *= dfs2(node, n) * fact.fact_inv(fact.fact[size[node]])
    res %= MOD
    dp[n] = res
    return res
dfs2(1)
# print(dp)

# step2 還元
ans = [0 for _ in range(n+1)]
inv_1 = fact.fact_inv(fact.fact[n-1])
def dfs3(num, par=-1):
    if par != -1:
        res = dp[num] * fact.fact_inv(fact.fact[size[num] - 1]) * \
            fact.fact[n-1] * ans[par] * inv_1 * \
            fact.fact[n-size[num]-1] * fact.fact[size[num]] * \
            fact.fact_inv(dp[num]) * \
            fact.fact_inv(fact.fact[n-size[num]]) % MOD
        ans[num] = res
    else:
        ans[num] = dp[num]
    for node in edges[num]:
        if node == par:
            continue
        dfs3(node, num)
dfs3(1)
print("\n".join(list(map(str, ans[1:]))))


Measured memory_bytes: 175176
c11,c12,c13=list(map(int,input().split()))
c21,c22,c23=list(map(int,input().split()))
c31,c32,c33=list(map(int,input().split()))
for i in range(min(c11,c12,c13)+1):
  t1=c11-i
  t2=c12-i
  t3=c13-i
  if c21-t1==c22-t2 and c21-t1==c23-t3 and c31-t1==c32-t2 and c31-t1==c33-t3:
    print("Yes")
    break
else:
  print("No")

Measured memory_bytes: 3064
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>

using namespace std;
using vec = vector<int>;


vec parent;

int find(int i)
{
	if (parent[i] == i)return i;
	return parent[i] = find(parent[i]);
}

void unite(int i, int j)
{
	i = find(i);
	j = find(j);

	parent[i] = j;
}


int main()
{
	int N, M;
	cin >> N >> M;
	parent = vec(N);

	for (int i = 0; i < N; ++i)
	{
		parent[i] = i;
	}

	for (int i = 0; i < M; ++i)
	{
		int X, Y, Z;
		cin >> X >> Y >> Z;
		--X;
		--Y;
		unite(X, Y);
	}

	int ans = 0;
	for (int i = 0; i < N; ++i)
	{
		ans += parent[i] == i;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
let () =
  let n = Scanf.sscanf (input_line stdin) "%d" (fun a -> a) in
  let x1 = float_of_int n /. 1.08 in
  let x1' = int_of_float x1 in
  let x2' = x1' + 1 in
  let ans =
    if int_of_float (float_of_int x1' *. 1.08) = n then string_of_int x1' 
    else if int_of_float (float_of_int x2' *. 1.08) = n then string_of_int x2'
    else ":("
  in
  print_string ans;
  print_newline ()


Measured memory_bytes: 384
/*
AOJ: Rummy
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2102&lang=jp
着席位置 教卓から見て左中央
*/

#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
using namespace std;

const double pi = acos(-1);

#define nyan cout<<"(=^•ω•^=)"<<endl;
#define int long long

pair<int, char> card[10];
//第一要素がランク，第二要素がスート

bool setting(int a, int b, int c){
    if(a==b&&b==c)return true;
    if(b==a+1&&c==b+1)return true;
    return false;
}

signed main(){
    int Query;cin>>Query;
    for(int q=0;q<Query;q++){
        for(int i=0;i<9;i++)cin>>card[i].first;
        for(int i=0;i<9;i++)cin>>card[i].second;
        sort(card,card+9);
        bool ans=false;
        while(next_permutation(card,card+9)){
            bool flag=false;
            for(int i=0;i<3;i++){
                if(card[3*i].second!=card[3*i+1].second)flag=true;
                if(card[3*i+1].second!=card[3*i+2].second)flag=true;
                if(!setting(card[3*i].first,card[3*i+1].first,card[3*i+2].first))flag=true;
            }
            if(flag)continue;
            ans=true;
        }
        cout<<(ans?"1":"0")<<endl;
    }
    return 0;
}


Measured memory_bytes: 3012
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    final long X = sc.nextLong();
    sc.close();
    int counter = 0;
    long now = 100;
    while(now<X) {
    	now += (long)(now/100);
    	counter++;
    }
    System.out.println(counter);
  }
}

Measured memory_bytes: 35660
from bisect import bisect_left
import sys
def main():
    input = sys.stdin.readline
    N = int(input())
    *A, = map(int, input().split())
    G = [[] for _ in range(N)]
    for _ in range(N - 1):
        u, v = map(int, input().split())
        u, v = u - 1, v - 1
        G[u].append(v)
        G[v].append(u)

    INF = 10**10
    tbl = [INF] * N
    stk = [(0, 0)]
    ans = [0] * N
    mx = -1
    while stk:
        s, a = stk.pop()
        if s == 0:
            v = a
            i = bisect_left(tbl, A[v])
            mx = max(mx, i)
            ans[v] = mx + 1
            stk.append((1, (i, tbl[i])))
            tbl[i] = A[v]
            for to in G[v]:
                if ans[to] > 0: continue
                stk.append((0, to))
        else:
            idx, val = a
            tbl[idx] = val
            if val == INF: mx = idx - 1
    for a in ans:
        print(a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 135048
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
#define int long long
int gd(int d, vector<int> w){
	if(w[(d+1)%4]==1) return (d+1)%4;
	else if(w[d]==1) return d;
	else if(w[(d+3)%4]==1) return (d+3)%4;
	else return (d+2)%4;
};
signed main(){
	char buf[256];
	vector<vector<vector<int>>> rms(5,vector<vector<int>>(5, vector<int>(4,0)));
	for(int i=0;i<9;i++){
		scanf("%s",buf);
		if(i%2==0){
			for(int j=0;j<4;j++){
				if(buf[j]=='1'){
					rms[i/2][j][0] = 1;
					rms[i/2][j+1][2] = 1;
				}
			}
		}else{
			for(int j=0;j<5;j++){
				if(buf[j]=='1'){
					rms[i/2][j][3] = 1;
					rms[i/2+1][j][1] = 1;
				}
			}
		}
	}
	int x=0,y=0,d=0;
	while(true){
		d = gd(d,rms[y][x]);
		if(d==0){cout<<"R"; x++;}
		else if(d==1){cout<<"U"; y--;}
		else if(d==2){cout<<"L"; x--;}
		else {cout<<"D"; y++;}
		if(x==0&&y==0) break;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3084
#include<stdio.h>

int f(int n){
  int i;
  for(i=2;i*i<=n;i++)
    if(n%i==0) return 0;
  return 1;
}

int main(){
  int n,t,ans;
  ans = 0;
  scanf("%d",&n);
  while(n--){
    scanf("%d",&t);
    ans+=f(t);
  }
  printf("%d\n",ans);
}



Measured memory_bytes: 2124
using System;
using System.Collections.Generic;

class Program {
  static void Main() {
    var d = new Dictionary<char, char[]> {
      ['A'] = new char[] { 'X', 'Y' },
      ['X'] = new char[] { '-', 'Z' },
      ['Y'] = new char[] { 'X', '-' },
      ['Z'] = new char[] { 'W', 'B' },
      ['W'] = new char[] { 'B', 'Y' },
      ['B'] = new char[] { 'Y', 'X' }
    };
    var p = "";
    while ((p = Console.ReadLine()) != "#") {
      char a = 'A';
      foreach (var c in p) {
        if (c == '0') a = d[a][0];
        else  a = d[a][1];
        if (a == '-') break;
      }
      Console.WriteLine(a == 'B' ? "Yes" : "No");
    }
  }
}


Measured memory_bytes: 17936
#include<cstdio>
#include<vector>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=100000+5;
int vec[maxn];
int main()
{
	vector<int> ve;
	int t,num,maxi,sum,beg;
	while(scanf("%d",&t)==1)
	{
		ve.clear();
		memset(vec,0,sizeof(vec));
		beg=0;
		for(int i=0;i<t;i++)
		{
			scanf("%d",&num);
			if(beg<num) beg=num;
			vec[num]++;
		}
			for(int i=0;i<=beg;i++)
		{
		if(vec[i]==0) continue;
		maxi=vec[i]+vec[i+1]+vec[i+2];
		ve.push_back(maxi);
		}
		sort(ve.begin(),ve.end());
		cout<<ve[ve.size()-1]<<endl;
	}
	return 0;
}

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

int main(){
  int x;
  cin >> x;
  if(400<=x&&x<=599){
    cout << 8 << endl;
  }
  else if(600<=x&&x<=799){
    cout << 7 << endl;
  }
  else if(800<=x&&x<=999){
    cout << 6 << endl;
  }
  else if(1000<=x&&x<=1199){
    cout << 5 << endl;
  }
  else if(1200<=x&&x<=1399){
    cout << 4 << endl;
  }
  else if(1400<=x&&x<=1599){
    cout << 3 << endl;
  }
  else if(1600<=x&&x<=1799){
    cout << 2 << endl;
  }
  else if(1800<=x&&x<=1999){
    cout << 1 << endl;
  }
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
 
#define pb push_back
typedef long long int ll;
typedef vector<ll> vl;
typedef map<ll,ll> ii;
typedef vector<vl> vvl;

void sieve(ll x,vl &v){
    ll i=2;
    while(i*i<=x){
        if(v[i]){
            for(ll j=i+i;j<=x;j+=i){
                v[j]=0;
            }
        }
        i++;    
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    vl v(1000001,1);
    sieve(1000001,v);
    
    ll a,b;cin>>a>>b;
    set<ll> s,s0;
    for(int i=2;i<=sqrt(a);i++){
        if(!(a%i)){
            while(a%i==0){
                a/=i;
            }
            s.insert(i);
        }
    }
    if(a>=2) s.insert(a);
    
    for(int i=2;i<=sqrt(b);i++){
        if(!(b%i)){
            while(b%i==0){
                b/=i;
            }
            s0.insert(i);
        }
    }
    if(b>=2) s0.insert(b);
    ll k=max(s.size(),s0.size());
    vl v2(k);
    auto yo=set_intersection(s0.begin(),s0.end(),s.begin(),s.end(),v2.begin())-v2.begin();
    cout<<yo+1;
    
    
    return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh
ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}
//char a[55][55];
int dx[] = {1,0,-1,0,1,1,-1,-1};
int dy[] = {0,1,0,-1,1,-1,-1,1};
ll a[100];
int main()
{
	dhoom;
	int n;
	cin >> n;
	int ans = 9999999;
	for(int i = 0 ; i < n ; i++){
		int x;
		cin >> x;
		int cnt = 0;
		while(x % 2 == 0){	
			x /= 2;
			cnt++;
		}
		ans = min(ans , cnt);
	}
	cout << ans << endl;
	return 0;
}


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

#define rp(i, k, n) for (ll i = k; i < n; i++)
#define ll  long long

ll mod = 1e9 + 7;

int main() {
    int x, y;
    cin >> x >> y;
    printf("%d", x + y/2);
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using static kyoupuro.Input;
using static kyoupuro.MyMath;

namespace kyoupuro {

    class MainClass {

        public static void Main() {
            var N = NextInt();
            var v = IntList();
            var c = IntList();

            Console.WriteLine(v.Zip(c, (a, b) => a - b).Where(x => x > 0).Sum());

        }
    }

    class MyMath {
        public const long mod = 1000000007;

        public static long Gcd(long a, long b) {
            return b == 0 ? a : Gcd(b, a % b);
        }

        public static List<long> Factor(long n) {
            var list = new List<long>();
            n = DivideToLimit(n, 2, list);
            n = DivideToLimit(n, 3, list);
            long sqrt = Sqrt(n);
            for (int i = 5; i <= n && i <= sqrt; i += 4) {
                n = DivideToLimit(n, i, list);
                i += 2;
                n = DivideToLimit(n, i, list);
            }
            if (n > 1) list.Add(n);
            return list;
        }

        public static long Sqrt(long n) {
            if (n < 0) return 0;
            long a = 0, tmp = 0, b = 0;
            for (int i = 62; i >= 0; i -= 2) {
                tmp = (b << 1) + 1 <= (n >> i) ? 1 : 0;
                a = a << 1 | tmp;
                n -= (((b << 1) + 1) * tmp) << i;
                b = (b << 1) + tmp + tmp;
            }
            return a;
        }

        static long DivideToLimit(long divisor, long dividend, List<long> list) {
            while (divisor % dividend == 0) {
                list.Add(dividend);
                divisor /= dividend;
            }
            return divisor;
        }
    }

    class Input {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line() {
            return Console.ReadLine();
        }

        public static int NextInt() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return int.Parse(enumerator.Current);
        }

        public static long NextLong() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return long.Parse(enumerator.Current);
        }

        public static string[] StrArr() {
            return Line().Split(' ');
        }

        public static List<int> IntList() {
            return StrArr().Select(int.Parse).ToList();
        }

        public static List<long> LongList() {
            return StrArr().Select(long.Parse).ToList();
        }
    }
}

Measured memory_bytes: 13524
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
ll MOD  = 1000000007;
vector<int> dy = {0,0,1,-1};
vector<int> dx = {1,-1,0,0};

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

ll N, M, K;
int main(void){
    COMinit();
    cin >> N >> M >> K;
    ll ans = 0;
    
    for(int d = 0; d <= M - 1; d++){
        ans += (M - d) % MOD * N % MOD * N % MOD * d % MOD;
        ans %= MOD;
    }
    
    for(int d = 0; d <= N - 1; d++){
        ans += (N - d) % MOD * M % MOD * M % MOD * d % MOD;
        ans %= MOD;
    }
    ans *= comb(N * M - 2, K - 2);
    ans %= MOD;
    ans += MOD;
    ans %= MOD;
    cout << ans << endl;
}


Measured memory_bytes: 4992
#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
// -----------------------------------------------

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($arg:expr),*) => {
        #[cfg(debug_assertions)]
        $(writeln!(stderr(), "{} = {:?}", stringify!($arg), $arg).unwrap());*
    };
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);

    let mut ws = HashSet::new();
    let w = rl();
    let mut last = *w.as_bytes().last().unwrap();
    ws.insert(w);
    let mut ok = true;

    for _ in 1..N {
        let w = rl();
        if w.as_bytes()[0] != last {
            ok = false;
            break;
        }
        if ws.contains(&w) {
            ok = false;
            break;
        }

        last = w.as_bytes().last().cloned().unwrap();
        ws.insert(w);
    }

    println!("{}", if ok { "Yes" } else { "No" })
}


Measured memory_bytes: 4352
from collections import Counter
 
 
def solve(nums):
    counts = sorted([pair for pair in Counter(nums).items() if pair[1] >= 2], reverse=True)
 
    if len(counts) == 0:
        return 0
    elif len(counts) == 1:
        (val, cnt) = counts[0]
        return 0 if cnt < 4 else val * val
    else:
        (val1, cnt1) = counts[0]
        (val2, cnt2) = counts[1]
        return val1 * val2 if cnt1 < 4 else val1 * val1
 
 
if __name__ == '__main__':
    n = input()
    a = [int(i) for i in input().split()]
    print(solve(a))

Measured memory_bytes: 18592
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

bool isPrime(int x){
    if(x==1)return 0;
    if(x==2)return 1;
    if(x%2==0)return 0;
    for(int i=3;i*i<=x;i++)if(x%i==0)return 0;
    return 1;
}
int main() {
    int n; cin >> n;
    int cnt=0;
    map<string,int>m;
    rep(i,n){
        string s;
        cin >> s;
        m[s]++;
    }

    cout << m.size() <<endl;
    return 0;
}


Measured memory_bytes: 19256