akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict
n, p = map(int, input().split())


def fctr_d(n):
    c = 0
    r = int(n**0.5)
    f = defaultdict(int)
    for i in range(2, r+2):
        while n % i == 0:
            c += 1
            n = n//i
        if c != 0:
            f[i] += c
            c = 0
    if n != 1:
        f[n] += 1
    return f


d = fctr_d(p)
ans = 1
for key, v in d.items():
    if v >= n:
        a = v // n
        ans *= key**a
print(ans)



Measured memory_bytes: 9428
import sys
si = sys.stdin.readline


def main():
    [n, k] = [int(e) for e in si().split()]
    trace = dict()
    for i in range(1, n+1):
        trace[i] = 0

    l = [int(e) for e in si().split()]
    i, cnt = 1, 0
    while k > 0:
        k -= 1
        cnt += 1
        i = l[i-1]
        if i == 1 or trace[i] != 0:
            cy = cnt-trace[i]
            k %= cy
            break
        trace[i] = cnt
    while k > 0:
        i = l[i-1]
        k -= 1
    print(i)


if __name__ == '__main__':
    main()


Measured memory_bytes: 48592
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
typedef long long LL;
#define int LL
const int mo=1e9+7;
typedef pair<int,int> pii;
#define gc() getchar()
template<typename _T>
void read(_T &x){
	_T f=1;x=0;char s=gc();
	while(s>'9'||s<'0'){if(s=='-')f=-1;s=gc();}
	while(s>='0'&&s<='9'){x=(x<<3)+(x<<1)+(s^48);s=gc();}
	x*=f;
}
template<typename _T>
_T Fabs(_T x){return x<0?-x:x;}
char str[5];
signed main(){
	scanf("%s",str);
	if(str[1]=='B')puts("ARC");
	else puts("ABC");
	return 0;
}

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

#define rep(i, first, to) for(ll i = first; i < to; ++i)

using namespace std;
typedef long long ll;

int a[3];
void solve() {
	rep(i, 0, 3) {
		cin >> a[i];
	}
	int sum = 0;
	int maxi = -1;
	rep(i, 0, 3) {
		sum += a[i];
		maxi = max(maxi, a[i]);
	}
	if (sum == 2 * maxi) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

int main() {
	solve();
	return 0;
}

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

int main(){

  int n;
  char s[15];
  long long ans = 0;
  long long sum = 0;
  int i,j;

  scanf("%s", s);
  n = strlen(s) - 1;

  for(i = 0;i < 1 << n;i++){
    sum = s[0] - '0';
    for(j = 0;j < n;j++){
      if(i >> j & 1){
        ans += sum;
        sum = (s[j + 1] - '0');
      }

      else sum = 10*sum + (s[j + 1] - '0');
    }

    ans += sum;
  }
  
  printf("%lld\n", ans);

  return 0;
}

Measured memory_bytes: 128
n = int(input())
a = list(map(int,input().split()))
a.sort()
ok = [1]*(10**6+1)
ans = 0
for i in range(n):
    if ok[a[i]]:
        if i < n-1:
            if a[i+1] != a[i]:
                ans += 1
        else:
            ans += 1
        for j in range(1,10**6//a[i]+1):
            ok[a[i]*j] = 0
print(ans)

Measured memory_bytes: 96892
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner S = new Scanner(System.in);
		int N = S.nextInt();
		int M = S.nextInt();
		int[] A = new int[N];
		int[] A_num = new int[N];
		int[] B = new int[M];
		int answer = 0;
		
		for(int i = 0;i < N;i++){
			A[i] = S.nextInt();
		}
		
		for(int i = 0;i < M;i++){
			B[i] = S.nextInt();
		}
		
		for(int j = 0;j < M;j++){
			int s = B[j];
			for(int i = 0;i < N;i++){
				if(s >= A[i]){
					A_num[i]++;
					break;
				}
			}
		}
		
		int max = A_num[0];
		for(int i = 0;i < N;i++){
			if(max <= A_num[i]){
				max = A_num[i];
				answer = i + 1;
			}
		}
		
		/*
		for(int i = 0;i < N;i++){
			System.out.print(" "+A_num[i]);
		}
		
		System.out.println();
		*/
		
		System.out.println(answer);
		
	}

}

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

inline int findstr(const char* s, const int& begin, const int& end, const char* t, const int& tl) {
  for (int i = begin; i <= end - tl;) {
    for (int j = 0; j < tl; ++j) {
      if (s[i + j] != t[j]) goto cont;
    }
    return i;
  cont:
    ++i;
  }
  return -1;
}
char s[5001], t[6];
int main() {
  int k;
  scanf("%s", s);
  scanf("%d", &k);
  const int n = strlen(s);
  for (char c = 'a'; c <= 'z'; ++c) {
    t[0] = c;
    int l0 = findstr(s, 0, n, t, 1);
    if (l0 < 0) continue;
    if (k == 1) {
      printf("%s\n", t);
      return 0;
    }
    --k;
    for (char c = 'a'; c <= 'z'; ++c) {
      t[1] = c;
      int l1 = findstr(s, l0, n, t, 2);
      if (l1 < 0) continue;
      if (k == 1) {
        printf("%s\n", t);
        return 0;
      }
      --k;
      for (char c = 'a'; c <= 'z'; ++c) {
        t[2] = c;
        int l2 = findstr(s, l1, n, t, 3);
        if (l2 < 0) continue;
        if (k == 1) {
          printf("%s\n", t);
          return 0;
        }
        --k;
        for (char c = 'a'; c <= 'z'; ++c) {
          t[3] = c;
          int l3 = findstr(s, l2, n, t, 4);
          if (l3 < 0) continue;
          if (k == 1) {
            printf("%s\n", t);
            return 0;
          }
          --k;
          for (char c = 'a'; c <= 'z'; ++c) {
            t[4] = c;
            int l4 = findstr(s, l3, n, t, 5);
            if (l4 < 0) continue;
            if (k == 1) {
              printf("%s\n", t);
              return 0;
            }
            --k;
          }
          t[4] = 0;
        }
        t[3] = 0;
      }
      t[2] = 0;
    }
    t[1] = 0;
  }
}


Measured memory_bytes: 1660
#include<iostream>
#include<math.h>
using namespace std;
#include<vector>
//√640= 25が最大
int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    long long L,R;
    cin >> L >> R;
    long long minimum= 2018;
    for(long long i=L; i<=R-1; i++){
        for(long long j=i+1; j<=R; j++){
            minimum= min(minimum, (i*j)%2019);
            if(minimum==0) { cout << minimum << endl; return 0;}
        }
    }    
    cout << minimum << endl;
}

Measured memory_bytes: 888
function Main(input) {
  input = input.split("\n");
  var n = parseInt(input[0]);
  tmp = input[1].split(" ");
  a = new Array(n);
  var odd=0;
  var even=0;
  var four=0;
  for(i=0;i<n;i++){
    a[i]=parseInt(tmp[i]);
    if(a[i]%4==0){
      four++;
    }else if(a[i]%2==0){
      even++;
    }else{
      odd++;
    }
  }
  var ans ="No";
  if(odd<=four){
    ans="Yes";
  }else if(four+1==odd&&even==0){
    ans="Yes";
  }

  console.log('%s', ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 17484
#include <bits/stdc++.h>
using namespace std;
int main(){

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



Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(){
    ll n;
    cin >> n;
    ll a,b;
    for(ll i=sqrt(n);i>=1;i--){
        if(n%i==0){
            a=i;
            b=n/i;
            break;
        }
    }
    cout << a+b-2 << endl;
    return 0;
}

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

int main(){
  int N;
  string S;
  cin >> N >> S;
  int count = 0;
  for (int i=0; i<10; i++) {
    for (int j=0; j<10; j++) {
      for (int k=0; k<10; k++) {
        int key = i;
        int check = 0;
        for (int l=0; l<N; l++) {
          string c{S.at(l)};
          if (stoi(c) == key) {
            if (check == 0) {
              key = j;
              check++;
            }
            else if (check == 1) {
              key = k;
              check++;
            }
            else {
              count++;
              break;
            }
          }
        }
      }
    }
  }
  cout << count << endl;
}

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

int main(){
  int N,Y; cin >>N >>Y;
  int x,y,z;

  for(x=0; x<=N; x++){
    if(Y<10000*x) break;
    for(y=0; y<=N-x; y++){
      if(Y<10000*x+5000*y) break;
      z = N-x-y;
      if(Y==10000*x+5000*y+1000*z){
        cout << x << " " << y << " " << z << endl;
        return 0;
      }
    }
  }

  cout << -1 << " " << -1 << " " << -1 << endl;
  return 0;
}


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

const int LIMIT = 200000;

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

    int n;
    int R[LIMIT];
    int max = -2000000000;
    int min;
    std::cin >> n;
    for (int i = 0; i < n; ++i) {
        std::cin >> R[i];
    }
    min = R[0];
    for (int i = 1; i < n; ++i) {
        max = std::max(max, R[i] - min);
        min = std::min(min, R[i]);
    }
    std::cout << max << std::endl;
}



Measured memory_bytes: 3936
n = int(input())

lets = [chr(i) for i in range(ord("a"), ord("z") + 1)]
ans = []


def dfs(s, l, mx):
    if l == n:
        ans.append(s)
        return

    for i in range(mx + 2):
        dfs(s + lets[i], l + 1, max(mx, i))


dfs("", 0, -1)
print(*ans, sep="\n")


Measured memory_bytes: 14464
N = int(input())

All = []
def enumeration(a="0", b = 1):
    if len(a) == N:
        All.append(a)
    else:
        for i in range(len(set(a)) + 1):
            enumeration(a + str(i), b+1)

enumeration()
for i in range(len(All)):
    All[i] = list(All[i])
    for p in range(len(All[i])):
        All[i][p] = chr(97 + int(All[i][p]))
    print("".join(All[i]))

Measured memory_bytes: 29072
#include <stdio.h>

int main(void)
{
    int s = 100000;
    int n, i;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) {
        s = (int)((s * 1.05 + 999) / 1000) * 1000;
    }
    
    printf("%d\n", s);
    
    return 0;
}

Measured memory_bytes: 0
n, m = map(int, input().split())
if n == 1 and m == 1:
    print(1)
elif n >= 2 and m == 1:
    print(n-2)
elif n == 1 and m >= 2:
    print(m-2)
elif n >= 2 and m >= 2:
    # 4隅が表、4隅以外の外周が表、それ以外が裏
    # つまり外周を取り除いたところが裏
    print((n-2)*(m-2))


Measured memory_bytes: 2940
#include<iostream>
#include<cassert>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
#define MAX 100 
using namespace std;

struct You
{//??????????????????????????§?¨????dx[(dir+1)%4],dy[(dir+1)%4]??????????????´???
  int x,y,dir;
  You(int x=-inf,int y=-inf):x(x),y(y),dir(0){}
};

char G[MAX][MAX];
int dx[] = {+1,+0,-1,+0};
int dy[] = {+0,+1,+0,-1};

void init()
{
  rep(i,MAX)rep(j,MAX)G[i][j] = '.';
}

void makeGraph()
{
  string line;
  int x;
  REP(y,1,10)
    {//odd -> yoko, even -> tate
      cin >> line;
      x = (y%2?1:0);
      rep(i,line.size())
	{
	  if(line[i] == '1')
	    {
	      G[y][x] = (y%2?'-':'|');
	      if(y%2) G[y][x-1] = G[y][x+1] = 'o';
	      else    G[y+1][x] = G[y-1][x] = 'o';
	    }
	  x += 2;
	}
    }
}

void print()
{
  rep(i,11)
    {
      rep(j,11)
	{
	  cout << G[i][j];
	}
      cout << endl;
    }
  cout << endl;
}

void compute()
{
  You you(0,0);
  bool fir = true;
  while(true)
    {
      int x = you.x,y = you.y,dir = you.dir;
      int hx = x + dx[(dir+1)%4],hy = y + dy[(dir+1)%4];
      if(!fir && hx == 0 && hy == 1)
	{
	  cout << '\n';
	  return;
	}
      fir = false;

      int nx = x + dx[dir],ny = y + dy[dir];
      hx += dx[dir],hy += dy[dir];
      assert(G[ny][nx] != 'o');

      if(G[ny][nx] == '|' || G[ny][nx] == '-')
	{
	  dir = (dir + 3)%4;
	  you.dir = dir;
	}
      else if(G[hy][hx] == '.')
	{
	  dir = (dir + 1)%4;
	  you.x = nx + dx[dir], you.y = ny + dy[dir],you.dir = dir;	  
	}
      else if(G[hy][hx] == 'o' || G[hy][hx] == '-' || G[hy][hx] == '|')
	{
	  you.x += dx[dir],you.y += dy[dir];
	}

      hx = you.x + dx[(dir+1)%4], hy = you.y + dy[(dir+1)%4];

      if(G[hy][hx] != 'o')
	cout << (dir==0?'R':(dir==1?'D':(dir==2?'L':'U')));
    }
}

int main()
{
  init();
  makeGraph();
  compute();
  return 0;
}

Measured memory_bytes: 1168
#include<stdio.h>
int main()
{
	int k;
	scanf("%d",&k);
	if(k==1)
	{
		printf("1\n1\n");
		return 0;
	}
	int n=(((k+3)>>2)<<1);
	printf("%d\n",n);
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			int val=(i+j)%n+1;
			if(i&1)
			{
				val+=n;
				if(val>k)
				{
					val-=n;
				}
			}
			printf("%d",val);
			if(j==n-1)
			{
				putchar('\n');
			}
			else
			{
				putchar(' ');
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
using namespace std;

void solve()
{
  string a,b,c;
  cin >> a >> b >> c;

  if(a[a.length() - 1] == b[0] && b[b.length() - 1] == c[0])
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

int main(){cin.tie(0);ios_base::sync_with_stdio(false);solve();return 0;}


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

ll n;

inline ll read(){									//快读 
	ll s = 0, w = 1;
	char ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar()) w *= ch == '-' ? -1 : 1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) s = s * 10 + ch - '0';
	return s * w;
}

inline void work(){
	n = read();										//同题目中的r 
	printf("%.14f\n", 2 * n * 3.14159265358979);	//代入公式 
}

int main(){
	work();
	return 0;
}

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

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;

ll N;
ll d[100010];
int main(){
	cin >> N;
	REP(i,0,N){
		cin >> d[i];
	}
	sort(d,d+N);
	ll ml = d[N/2-1];
	ll mr = d[N/2];
	p(mr-ml);

	return 0;
}

Measured memory_bytes: 1024
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let n : usize = read();
    let v :Vec<usize> = read_vec();
    let mut c = 0;
    for i in 0..n {
        if v[i] != i+1 {
            c += 1;
        }
    }
    if c > 2 || c == 1 {
        println!("NO");
    }
    else {
        println!("YES");
    }
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const long long INF=9000000000000000;
const int maxn=200010;
typedef long long ll;
ll sum1[maxn],sum2[maxn],a[maxn];
int main()
{
    //freopen("text.in","r",stdin);
    ll ans,b,tmp;
    int i,n;
    scanf("%d",&n);
    for (i=1;i<=n;i++) {
        scanf("%lld",&a[i]);
        a[i]=a[i]-i;
    }
    sort(a+1,a+n+1);
    memset(sum1,0,sizeof(sum1));
    memset(sum2,0,sizeof(sum2));
    for (i=1;i<=n;i++) {
        sum1[i]=sum1[i-1]+a[i];
    }
    for (i=n;i>=1;i--) {
        sum2[i]=sum2[i+1]+a[i];
    }
    ans=INF;
    for (i=1;i<=n;i++) {
        b=a[i];
        tmp=i*b-sum1[i]+sum2[i+1]-b*(n-i);
        ans=min(ans,tmp);
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 4864
n = int(input())
dat_a = map(int, input().split())
dat_b = map(int, input().split())
dat_c = map(int, input().split())
dat_a = list(dat_a)
dat_b = list(dat_b)
dat_c = list(dat_c)
last = -100
res = 0
for i in range(n):
    a = dat_a[i] - 1
    res += dat_b[a]
    if last == (a - 1):
        res += dat_c[last]
    last = a
print(res)


Measured memory_bytes: 38384
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793
 
   
int main(){
  ll n;
  cin >> n;
  ll cnt=0;
  for(ll i=1;i<n;i++){
    ll x=(n-1)/i;
    cnt+=x;
  }
  cout << cnt << endl;
} 
    

Measured memory_bytes: 3644
#include <stdio.h>
int main()
{
	int a,b;
	char c;
	while(scanf("%d %c %d",&a,&c,&b)!=EOF&&c!='?')
	{
		if(c=='+')printf("%d\n",a+b);
		if(c=='-')printf("%d\n",a-b);
		if(c=='*')printf("%d\n",a*b);
		if(c=='/')printf("%d\n",a/b);
	}
	return 0;
}


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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x) cout << x << endl; exit(0);
#define IPT(v, n) REP(i, 0, n){ cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
const static ll INF = 1 << 30;

ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;

ll ans = 0;
ll sum = 0;
ll cnt = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;

double ave = 0.0;

int main() {
    cin >> n;
    vl a(n);
    NREP() {
        cin >> a[i];
    }

    ans = INF;
    REP(i, -101, 102) {
        REP(j, 0, n) {
            sum += pow(i - a[j], 2);
        }
        ans = min(ans, sum);
        sum = 0;
    }
    MSG(ans)
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        // 標準入力からデータを読み込む準備
        Scanner sc = new Scanner(System.in);
        // 最初の文字の固まりを整数値と想定して読み込む
        while (true) {
            int H = sc.nextInt();
            int W = sc.nextInt();
            if (H == 0 && W == 0) {
                break;
            }
            // 二重ループ(forの中にfor)を書いて、H x W個の # を表示しよう！
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    System.out.print("#");
                }
                System.out.printf("\n");
            }
            System.out.printf("\n");
        }
    }
}


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

int main(){
  int W,H;
  string name;
  cin>>W>>H>>name;
  cout<<"+";
  for(int a=2;a<W;a++){cout<<"-";}
  cout<<"+"<<endl;
  
  for(int b=0;b<(H-3)/2;b++){cout<<"|";
    for(int a=2;a<W;a++){cout<<".";}
    cout<<"|"<<endl;
  }
  
  cout<<"|";
  for(int a=0;a<(W-3)/2;a++){cout<<".";}
  cout<<name;
  for(int a=0;a<(W-3)/2;a++){cout<<".";}
  cout<<"|"<<endl;

  for(int b=0;b<(H-3)/2;b++){cout<<"|";
    for(int a=2;a<W;a++){cout<<".";}
    cout<<"|"<<endl;
  }

  cout<<"+";
  for(int a=2;a<W;a++){cout<<"-";}
  cout<<"+"<<endl;

  return 0;
}
    
  
  
    
    



Measured memory_bytes: 3140
#include <bits/stdc++.h>
#include <iomanip>
 
using namespace std;
 
typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PLDLD;
typedef vector<int> VI;
typedef vector<char> VB;
 
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define ALL(a) a.begin(),a.end()
 
const LD eps=1e-10;
const long long INFLL=(LL)(1e9)*(LL)(1e9);
const int INF=1e9;
 
template<class T>
void chmin(T& a, const T b)
{
	if(a>b)
		a=b;
}
template<class T>
void chmax(T& a, const T b)
{
	if(a<b)
		a=b;
}
 
const LL pow(const LL p, const LL q)
{
	LL t=1;
	for(int i=0;i<q;i++)
		t*=p;
	return t;
}

template <typename T>
struct has_iter
{
	private:
		template <typename U>
		static constexpr true_type check(typename U::iterator*);
		template <typename U>
		static constexpr false_type check(...);

	public:
		static constexpr bool value = decltype(check<T>(nullptr))::value;
};

template<typename T, typename U = typename T::iterator>
void print(const T& container)
{
		auto&& first=begin(container), last=end(container);
		auto&& back=prev(last);
		for(auto e=first; e!=last; e=next(e))
			cout<<*e<<" \n"[e==back];
}

extern void* enabler;
template<typename Head, typename enable_if<!has_iter<Head>::value>::type*& = enabler>
void print(const Head& head)
{
	cout<<head<<endl;
}

template<typename Head, typename... Tail>
void print(const Head& head, const Tail&... tail)
{
	cout<<head<<" ";
	print(tail...);
}

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

template<typename T>
istream& operator >> (istream& is, vector<T>& vec)
{
	for(T& x: vec) is >> x;
	return is;
}

template<typename T>
vector<T> read(int n)
{
	vector<T> t(n);
	cin>>t;
	return t;
}

template<typename T>
T read()
{
	T t;
	cin>>t;
	return t;
}

int main()
{
	string s;
	cin>>s;
	int x,y;
	cin>>x>>y;
	vector<int> mx,my;
	int xm=0,ym=0;
	bool hori=1;
	bool first=1;
	int cnt=0;
	REP(i,s.size())
	{
		if(s[i]=='F')
		{
			cnt++;
		}
		else
		{
			if(first)
			{
				first=false;
				x-=cnt;
			}
			else if(hori)
			{
				mx.push_back(cnt);
				xm+=cnt;
			}
			else
			{
				my.push_back(cnt);
				ym+=cnt;
			}
			hori=!hori;
			cnt=0;
		}
	}
	if(first)
	{
		first=false;
		x-=cnt;
	}
	else if(hori)
	{
		mx.push_back(cnt);
		xm+=cnt;
	}
	else
	{
		my.push_back(cnt);
		ym+=cnt;
	}
	auto cx=[&](int x){return x+xm;};
	auto cy=[&](int y){return y+ym;};
	int nx=mx.size(), ny=my.size();
	VB dpx(xm*2+1), dpy(ym*2+1);
	dpx[cx(0)]=1;
	dpy[cy(0)]=1;
	REP(i,nx)
	{
		VB dp(xm*2+1);
		REP(j,xm*2+1)
		{
			if(j+mx[i]<=xm*2)
			dp[j+mx[i]]|=dpx[j];
			if(0<=j-mx[i])
			dp[j-mx[i]]|=dpx[j];
		}
		dpx=dp;
	}
	REP(i,ny)
	{
		VB dp(ym*2+1);
		REP(j,ym*2+1)
		{
			if(j+my[i]<=ym*2)
			dp[j+my[i]]|=dpy[j];
			if(0<=j-my[i])
			dp[j-my[i]]|=dpy[j];
		}
		dpy=dp;
	}
	/*
	REP(i,xm*2+1)
		cout<<(dpx[i]?1:0)<<" ";
	cout<<endl;
	REP(i,ym*2+1)
		cout<<(dpy[i]?1:0)<<" ";
	cout<<endl;*/
	if(!(0<=cx(x)&&cx(x)<=xm*2 && 0<=cy(y)&&cy(y)<=ym*2))
		print("No");
	else if(dpx[cx(x)]&&dpy[cy(y)])
		print("Yes");
	else
		print("No");
}


Measured memory_bytes: 256
s = input()
K = int(input())
ls = []
for i in range(len(s)):
  c = s[i]
  ls += [c]
  for j in range(1,K):
    if i+j>len(s)-1:
      break
    c += s[i+j]
    ls += [c]
ans = sorted(set(ls))
print(ans[K-1])

Measured memory_bytes: 40816
a, b, ab, x, y = (int(i) for i in input().split())  
if a + b <= (ab * 2):
    print(a*x+b*y)
else:
    num_ab = min(x,y)*2
    price = 0
    price += num_ab*ab + (x-num_ab/2)*a + (y-num_ab/2)*b
    price2 = 0
    price2 += max(x,y)*ab*2
    print(int(min(price,price2)//1))

Measured memory_bytes: 3064
n = int(input())

tmpl = [['']]
l = []
for i in range(1,10):
    #iは桁数
    tmp = []
    for x in tmpl[-1]:
        for s in '357':
            tmp.append(x+s)
    tmpl.append(tmp)
    l = l + tmp

def check(s):
    if all(s.count(x) for x in '357'):
        return True
    else:
        return False

ans = 0
for x in l:
    if int(x) <= n:
        if check(x):
            ans += 1
    else:
        break

print(ans)

Measured memory_bytes: 5492
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef long long ll;
typedef long long integer;
//////////////////////////////////////////////////
/*AtCoder Beginner Contest 108 (๑•﹏•๑｀)*/

int main(){
    int x1,y1,x2,y2,x3,y3,x4,y4;
    SCD2(x1,y1);
    SCD2(x2,y2);

    int dx,dy;
    dx = x2-x1; dy = y2-y1;
    x3 = x2-dy;
    y3 = y2+dx;
    x4 = x1-dy;
    y4 = y1+dx;
    printf("%d %d %d %d\n",x3,y3,x4,y4);
}

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

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

#define INF (INT_MAX/2-1)
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

int main(){
  int H,W;
  cin>>H>>W;
  vector<string>A(H);
  for(int i=0;i<H;i++)cin>>A[i];
  vector<vector<int>>ans(H,vector<int>(W,INF));
  for(int i=0;i<H;i++){
    int a=1;
    bool b=false;
    for(int j=0;j<W;j++){
      if(A[i][j]=='#')a=0,b=true;
      else if(b) ans[i][j]=a;
      a++;
    }
    b=false;
    a=1;
    for(int j=W-1;j>=0;j--){
      if(A[i][j]=='#')a=0,b=true;
      else if(b) ans[i][j]=(min(ans[i][j],a));
      a++;
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(A[i][j]=='#')ans[i][j]=0;
    }
  }

  for(int i=1;i<H;i++){
    for(int j=0;j<W;j++){
      ans[i][j]=min(ans[i][j],ans[i-1][j]+1);
    }
  }

  for(int i=H-2;i>=0;i--){
    for(int j=0;j<W;j++){
      ans[i][j]=min(ans[i][j],ans[i+1][j]+1);
    }
  }

  int res=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      res=max(res,ans[i][j]);
    }
  }
  cout<<res<<endl;
}



Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

int main() {
  int n, m; cin >> n >> m;
  vector<vector<int>> a(n, vector<int>(m+1, 0));

  REP(i, n){
    int k; cin >> k;
    REP(j, k){
      int t; cin >> t;
      t--;
      a[i][t]++;
    }
  }

  vector<bool> f(m+1, true);
  REP(i, n){
    REP(j, m){
      if(!a[i][j]) f[j] = false;
    }
  }

  cout << count(f.begin(), f.end(), true) - 1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
	int cnt=0,x=0;
	char c;
	string str,W;
	cin>>W;
	while(true){
		while(cin>>str){
			string ans;
			for(int i=0;i<str.size();i++){
				if('A'<=str[i] && str[i]<='Z'){
					c=str[i];
					c=c+32;
				}else if('a'<=str[i] && str[i]<='z'){
					c=str[i];
				}
				ans+=c;
			}
			if(ans==W){
				cnt++;
			}else if(str=="END_OF_TEXT"){
				break;
			}
		}
		break;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3180
a,b,k=map(int,input().split())
for i in range(k//2):
  if a%2==1:
    a-=1
  a=int(a/2)
  b=a+b
  if b%2==1:
    b-=1
  b=int(b/2)
  a=a+b
if k%2==1:
  if a%2==1:
    a-=1
  a=int(a/2)
  b=a+b
print(a,b)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main()
{
    long long int n;
    unsigned long long s=0,c;
    cin>>n;
    if(n==0)
    {
        cout<<0;
        return 0;
    }
    if(n>=500)
    {
        c=n/500;
        s=1000*c;
        n=n-(500*c);
    }
    if(n<500&&n!=0)
    {
       c=n/5;
       s+=(5*c);
    }
    cout<<s;
}


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

#define FOR0(i,n) for (int i = 0; i < n; i++)
#define FOR(i,j, n) for (int i = j; i < n; i++)
// bool isEven(ll n) {return (n%2!=0)?false:true;};
#define INF 1000000000 // 1 billion, safer than 2B for Floyd Warshall’s

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
// #define int ll

using namespace std;

//atcoder
//abc166

int main()
{
    int n, k, d;
    int a[110];
    bool got[110];

    cin>>n>>k;

    for (int i = 0; i < n; ++i)
    {
        got[i] = false;
    }

    for (int i = 0; i < k; ++i)
    {
        cin>>d;
        int temp;
        for (int j = 0; j < d; ++j)
        {
            cin>>temp;
            got[temp-1] = true;
        }
    }

    int count=0;

    for (int i = 0; i < n; ++i)
    {
        if(got[i]==false)
            count++;
    }
    cout<<count<<endl;

}

Measured memory_bytes: 3640
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
 
public class Main {
 
	public Main() {
		// TODO 自動生成されたコンストラクター・スタブ
	}
 
	public static void main(String[] args){
		Map <Integer,Integer> mapL = new HashMap<Integer,Integer> ();
 
		Scanner sc = new Scanner(System.in);
			// 整数の入力
			long a,b,c,d,r,m,max,num1,num2,num3,index;
			long result,result1,result2;
			a = sc.nextLong();
			b = sc.nextLong();
			c = sc.nextLong();
			d = sc.nextLong();
			sc.close();
			if(c>d) {
				m=c;
				r=d;
			}
			else {
				m=d;
				r=c;
			}
			for(index=0;;index++) {
				if(r==1) {
					result=1;
					break;
				}
				if(m%r==0) {
					result=r;
					break;
				}
				result=m%r;
				m=r;
				r=result;
			}
			max=c*d/result;
			//System.out.println(max);

			num1=b/c;
			num2=b/d;
			num3=b/max;
			result1=b-(num1+num2-num3);
			num1=(a-1)/c;
			num2=(a-1)/d;
			num3=(a-1)/max;
			result2=(a-1)-(num1+num2-num3);
			//System.out.println(result1);
			//System.out.println(result2);
			System.out.println(result1-result2);
			
 
			// 出力
 
	}
}

Measured memory_bytes: 21844
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int i,j,h,w;
    while(1){
        scanf("%d %d\n",&h,&w);
        
        if(h == 0 && w == 0){
            break;
        }
        else{
            for(i=1;i<=h;i++){
                for(j=1;j<=w;j++){
                    if(i != 1 && i != h && j != 1 && j != w){
                        printf(".");
                    }else{
                        printf("#");
                    }
                }
                printf("\n");
            }
            printf("\n");
        }
    }
    return 0;
}



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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;

int main() {
  ll n, m;
  cin >> n >> m;
  map<ll, ll> mp;
  set<ll> st;
  REP(i, m) {
    ll s, c;
    cin >> s >> c;
    if (st.count(s) && mp[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    mp[s] = c;
    st.insert(s);
  }

  if (st.count(1) && mp[1] == 0 && n != 1) {
    cout << -1 << endl;
    return 0;
  }

  string ans = "";
  REP(i, n) {
    ll t = mp[i + 1];
    if (n != 1 && t == 0 && i + 1 == 1) {
      ++t;
    }
    ans += '0' + t;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define int long long int
#define mod 1000000007
void fast(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
main()
{
	int a,b;
	cin>>a>>b;
	a-=2*b;
	a=max(a,(int)0);
	cout<<a<<endl;
}

Measured memory_bytes: 256
n = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))
ans = sum(b_list)
for i in range(n-1):
    if a_list[i] == a_list[i+1] - 1:
        ans += c_list[a_list[i]-1]
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdlib>
#include<cstdio>
#include<utility>
#include<list>
using namespace std;
int main(){
	bool same = false;
	string S;
	cin>>S;
	for(int i=0;i<S.size();i++){
		for(int j=0;j<S.size();j++){
			if(i == j)continue;
			if(S[i] == S[j]){
				same = true;
			}
		}
	}

	if(same!=true)cout<< "yes" <<endl;
	else cout<< "no" <<endl;
	return 0;
}


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

// @@ !! LIM()

void foo(int n, string prefix, string cand) {
  if (n == 0) {
    cout << prefix << "\n";
    return;
  }
  for (ll i = 0; i < (ll)cand.size(); i++) {
    ll lastIdx = (ll)cand.size() - 1;
    char lastChar = cand.at(lastIdx);
    if (i == lastIdx) {
      char xx[2];
      xx[0] = lastChar + 1;
      xx[1] = 0;
      foo(n - 1, prefix + lastChar, cand + string(xx));
    }else {
      foo(n - 1, prefix + cand.at(i), cand);
    }
  }
  
}

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  foo(N-1, "a", "ab");

  return 0;
}



Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
long long fac[201000], finv[201000], inv[201000]; 
long long MOD = 1000000007;  
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < 200500; 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;
    }
}
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
	int N, K; cin >> N >> K; COMinit(); 
	long long ans = 0; 
	for(int i = 0; i <= min(N-1, K); i++){
		ans += COM(N, i) * COM(N-1, i) % MOD; 
		ans %= MOD; 
	}
	cout << ans << endl; 	
}

Measured memory_bytes: 4992
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(N)]
count = 0
for i in range(N):
    wa = C
    for j in range(M):
        wa += A[i][j]*B[j]
    if wa > 0:
        count += 1
print(count)

    

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
using namespace std;
int main(int argc, char *argv[]) {
	int w,h;
	while (true) {
		cin>>w>>h;
		cin.ignore();
		if (w == 0 && h == 0) break;
		vector<string> map(h);
		for (int i=0;i<h;i++) getline(cin,map[i]);
		//for (int i=0;i<h;i++) cout<<map[i]<<endl;
		// search @
		int si,sj;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (map[i][j] == '@') {
					si = i; sj = j;
					break;
				}
			}
		}
		// bfs
		queue<pair<int,int> > mQue;
		int count = 0;
		mQue.push(make_pair(si,sj));
		vector<vector<bool> > check(h,vector<bool>(w,true));
		while (mQue.size() > 0) {
			int ti,tj;
			pair<int,int> tp = mQue.front();
			mQue.pop();
			ti = tp.first;
			tj = tp.second;
			//cout<<tj<<":"<<ti<<endl;
			// count
			if (check[ti][tj]) {
				count++;
				check[ti][tj] = false;
			}
			// deque
			if (ti-1>=0 && map[ti-1][tj] == '.' && check[ti-1][tj]) {
				mQue.push(make_pair(ti-1,tj));
			}
			if (tj+1<w && map[ti][tj+1] == '.' && check[ti][tj+1]) {
				mQue.push(make_pair(ti,tj+1));
			}
			if (ti+1<h && map[ti+1][tj] == '.' && check[ti+1][tj]) {
				mQue.push(make_pair(ti+1,tj));
			}
			if (tj-1>=0 && map[ti][tj-1] == '.' && check[ti][tj-1]) {
				mQue.push(make_pair(ti,tj-1));
			}
		}
		cout<<count<<endl;
	}
	return 0;
}

Measured memory_bytes: 4124
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format, std.datetime;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long K, N;
    scan(K, N);
    auto A = aryread();
    auto D = new long[](N + 1);
    D[0] = (K - A[$ - 1]) + A[0];
    foreach (i; 0 .. N)
    {
        D[i + 1] = A[i + 1] - A[i];
    }
    (K - D.reduce!(max)()).writeln();
}


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

using std::cin;
using std::cout;
using std::endl;
using std::vector;

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

  std::vector<vector<int>> text_list;
  std::vector<int> price_list;
  int32_t ans = INT32_MAX;

  for (int i = 0; i < N; i++) {
    int price;
    cin >> price;
    price_list.push_back(price);

    std::vector<int> point_list;
    for (int j = 0; j < M; j++) {
      int alg;
      cin >> alg;
      point_list.push_back(alg);
    }
    text_list.push_back(point_list);
  }

  int itr_num = std::pow(2, N);
  for (int bit = 0; bit < itr_num; bit++) {
    std::vector<int> learning(M, 0);
    int price = 0;

    for (int i = 0; i < N; i++) {
      if (bit & (1 << i)) {
        // i番目の参考書を購入
        auto target = text_list.at(i);
        for (uint32_t p = 0; p < target.size(); p++) learning[p] += target[p];
        price += price_list[i];
      }
    }

    // 条件を満たしているか判定
    if (price < ans) {
      bool ret(true);
      for (int i = 0; i < M; i++) {
        if (learning[i] < X) ret = false;
      }
      if (ret) ans = price;
    }
  }

  if (ans == INT32_MAX) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}


Measured memory_bytes: 4112
import sys
input=sys.stdin.readline
from itertools import accumulate
sys.setrecursionlimit(10**9)
mod=10**9+7
n=int(input())
A=list(map(int,input().split()))
S=list(accumulate([pow(i,mod-2,mod) for i in range(1,n+1)]))
ans=0
num=1
for i in range(2,n+1):
    num=num*i%mod
for i in range(n):
    ans+=A[i]*(S[i]+S[n-1-i]-1)%mod
ans=ans*num%mod
print(ans)

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

using namespace std;

int main(){
	long long int N;
	cin >> N;
	vector<long long int>A(N);
	for( size_t i = 0; i < N; i++ ){
		cin >> A[i];
	}
	vector<vector<long long int>>D(N + 1, vector<long long int>(20, -1));

	long long int ans = 0;
	vector<long long int>ansv(N);
	for( size_t i = 0; i < N; i++ ){
		long long int d = A[i];
		D[i + 1] = D[i];
		long long int maxv = -1;
		for( int j = 0; j < 20; j++ ){
			if( ( d >> j ) % 2 ){
				if( D[i + 1][j] != -1 ){
					maxv = max(D[i + 1][j], maxv);
				}
				D[i + 1][j] = i;
			}
		}
		long long int memo = i - maxv;
		if( i ){
			memo = min(memo, ansv[i - 1] + 1);
		}
		//cout << maxv << " " << memo << endl;
		ans += memo;
		ansv[i] = memo;
	}
	cout << ans << endl;
}


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

int main(){
    int a,b;
    cin >> a >> b;
    if(a<b){
        cout << "a < b" << endl;
    } else if(a>b){
        cout << "a > b" << endl;
    } else{
        cout << "a == b" << endl;
    }
    return 0;
}


Measured memory_bytes: 3044
from collections import Counter


def solve(N, As):
    c = Counter(As)
    two = sorted([i for i, v in c.items() if v >= 2])
    four = [i for i, v in c.items() if v >= 4]
    ans = 0
    if len(two) >= 2:
        ans = two[-1] * two[-2]
    if len(four):
        ans = max(max(four) * max(four), ans)
    return ans


if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))
    print(solve(N, As))


Measured memory_bytes: 18592
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define pint pair<int,int>

int n,m;
vector<vector<int>> to;

int dp1[101010],dp2[101010];
int ans[101010];

//1つ目のdfs
void dfs1(int a, int par ){ 
  
  int res = 1LL;
  
  for(auto ne : to[a] ){ 
    
    if( ne == par ){ continue;} 
    
    dfs1(ne,a);
    
    res = ( res * dp1[ne] ) % m;
    
    // +1済み
  }
  
  dp1[a] = (res+1)%m;
  
  return;
} 






//2つ目のdfs2
void dfs2(int a,int par){ 
  
  if( par == -1 ){ dp2[a] = 1LL; }
  
  vector<int> l_prod((int)to[a].size(),1);
  vector<int> r_prod((int)to[a].size(),1);
  
  for(int i = 0; i < (int)to[a].size(); i++){ 
    
    int res = 1LL;
    
    if( i-1 >= 0 ){ res *= l_prod[i-1];}
    
    if( to[a][i] != par ){ res *= dp1[to[a][i]];}
    
    res %= m;
    
    l_prod[i] = res;
    
  }
  
  
  for(int i = (int)to[a].size()-1; i >= 0; i--){ 
    
    int res = 1LL;
    
    if( to[a][i] != par ){ res *= dp1[to[a][i]];}
    
    if( i+1 < to[a].size()){ res  *= r_prod[i+1];}
    
    res %= m;
    
    r_prod[i] = res;
  }
  
  if(false){ 
    if( a == 0 && par == -1){ 
      cout << "L_prod check" << endl;
      for(int i = 0; i < (int)to[a].size(); i++){ 
        cout << l_prod[i] << " ";
      }
      cout << endl;
      cout << "R_prod check" << endl;
      for(int i = 0; i < (int)to[a].size(); i++){ 
        cout << r_prod[i] << " ";
      }
      
    }
    cout << endl;
    
  } 
  
  
  
  
  for(int j = 0; j  < (int)to[a].size(); j++){ 
    
    int res = 1LL;
    
    if( to[a][j] == par ){ continue;} 
    
    if( j-1 >= 0 ){ res *= l_prod[j-1];}
    if( j+1 < to[a].size()){ res *= r_prod[j+1];}
    
    res %= m;
    
    res = (res*dp2[a])%m;
    
    res = ( res+1 ) % m;
    
    dp2[to[a][j]] = res;
    //+1済み
    
    dfs2(to[a][j],a);
    
  }
  
  return ;
}
    

//３つ目のdfs 
void dfs3(int a, int par){ 
  
  int res = dp2[a];
  
  for(auto ne : to[a] ){ 
    
    if( ne == par ){ continue;} 
    
    res *= dp1[ne];
    res %= m;
    
    dfs3(ne,a);
    
  }
  
  ans[a] = res%m;
  
  return ;
}
  

signed main(void){ 
  
  cin >> n >> m;
  to.resize(n);
  for(int i = 0; i < n-1; i++){ 
    int a,b; cin >> a >> b;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  
  dfs1(0,-1);
  
  if(true){ 
  dfs2(0,-1);
  }
  
  dfs3(0,-1);
  
  if(true){ 
  for(int i = 0; i < n; i++){ 
    cout << ans[i] << endl;
  }
    
  }
  
  if(false){ 
    
    cout << endl;
    
    for(int i = 0; i < n; i++){ 
      cout << dp1[i] << " ";
    }
    
    cout << endl;
    
    for(int i = 0; i < n; i++){ 
      cout << dp2[i] << " " ;
    }
    
    cout << endl;
  } 
  
  return 0;
}
  

Measured memory_bytes: 19328
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
using pqueg = priority_queue<int, vector<int>, greater<int>>;
using pquel = priority_queue<int, vector<int>, less<int>>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
int lcm(int a, int b){
  return a / __gcd(a, b) * b;
}
int r_int(int a, int b){
  return rand() % b + a;
}
const lint mod=1e9+7;

double a, b;

lint f(lint x){
  return floor(a/b*x)-a*floor(x/b);
}

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

  cout << f(min(b-1, n)) << "\n";
  return 0;
}


Measured memory_bytes: 3708
n = int(input())
T = [0] + [None] * n
X = [0] + [None] * n
Y = [0] + [None] * n
for i in range(1, n + 1):
  T[i], X[i], Y[i] = map(int, input().split())

for i in range(len(T) - 1):
  dt = T[i + 1] - T[i]
  dx = abs(X[i + 1] - X[i])
  dy = abs(Y[i + 1] - Y[i])
  if (not (dt % 2 == (dx + dy) % 2 and (dx + dy) <= dt)):
    print('No')
    exit()

print('Yes')


Measured memory_bytes: 12388
use proconio::input;
use std::collections::HashMap;

fn main() {
    input! {
        n: usize, k: usize, s: usize, t: usize,
        a: [usize; n]
    }
    let mut dp = vec![HashMap::new(); k + 1];
    dp[0].insert(((1 << 18) - 1, 0), 1);
    for &a in &a {
        for i in (0..k).rev() {
            let mut ins = Vec::new();
            for (&(x, y), &p) in &dp[i] {
                let x = x & a;
                let y = y | a;
                if x & s != s || y | t != t {
                    continue;
                }
                ins.push(((x, y), p));
            }
            for (xy, p) in ins {
                *dp[i + 1].entry(xy).or_insert(0) += p;
            }
        }
    }
    let ans: u64 = (1..=k).filter_map(|i| dp[i].get(&(s, t))).sum();
    println!("{}", ans)
}


Measured memory_bytes: 118888
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

void debug_out() { std::cout << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

template <class T>
inline bool chmin(T &a, T b){
    if (a > b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmax(T &a, T b){
    if (a < b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m; cin >>n >> m;
    vector<int> a(n);
    int s = 0;
    rep(i,n){
        cin >> a[i];
        s += a[i];
    }
    s = (s+4*m-1)/(4*m);
    sort(rall(a));
    int flag = 0;
    rep(i,n){
        if(s<=a[i]) flag++;
    }
    if(flag>=m){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<cstdlib>
#include<set>

using namespace std;

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

int main(){
    int d, g;
    cin >> d >> g;
    int p[d], c[d];
    rep(i, d) cin >> p[i] >> c[i];
    int ans = 100000;
    for (int i = 0; i < (1 << d); i++){
        int num = 0;
        int score = 0;
        for (int j = 0; j < d; j++){
            if (((i >> j) & 1) == 1){
                num += p[j];
                score += p[j] * 100 * (j + 1) + c[j];
            }
        }
        // cout << score << " " << num << endl; 
        for (int j = d - 1; j >= 0; j--){
            if (score >= g) break;
            if (((i >> j) & 1) == 0){
                if (score + (p[j] - 1) * 100 * (j + 1) <= g){
                    score += (p[j] - 1) * 100 * (j + 1);
                    num += p[j] - 1;
                }else{
                    if ((g - score) % (100 * (j + 1)) == 0){
                        num += (g - score) / (100 * (j + 1));
                        score += (100 * (j + 1)) * ((g - score) / (100 * (j + 1)));
                        
                    }else{
                        num += (g - score) / (100 * (j + 1)) + 1; 
                        score += (100 * (j + 1)) * ((g - score) / (100 * (j + 1)) + 1);
                        // cout << g - score << endl;  
                        // cout << score << " " << num << endl;             
                    }
                }
            }
        }
        // cout << score << " " << num << endl;
        if (score >= g){
            ans = min(ans, num);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
from itertools import combinations

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
LIST = lambda: list(map(int, INPUT().split()))

sys.setrecursionlimit(10 ** 9)


def main():
    _ = INT()
    D = LIST()

    ans = 0
    for x, y in list(combinations(D, 2)): ans += x*y
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 39024