akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	h, w := iScan(), iScan()
	a := SScan(h)
	x, y := make(map[int]struct{}), make(map[int]struct{})
	for i := 0; i < h; i++ {
		f := true
		for j := 0; j < w; j++ {
			if string(a[i][j]) == "#" {
				f = false
			}
		}
		if f {
			x[i] = struct{}{}
		}
	}
	for j := 0; j < w; j++ {
		f := true
		for i := 0; i < h; i++ {
			if string(a[i][j]) == "#" {
				f = false
			}
		}
		if f {
			y[j] = struct{}{}
		}
	}
	for i := 0; i < h; i++ {
		if _, ok := x[i]; !ok {
			for j := 0; j < w; j++ {
				if _, ok := y[j]; !ok {
					fmt.Print(string(a[i][j]))
				}
			}
			fmt.Println("")
		}
	}
}


Measured memory_bytes: 1928
#include <iostream>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <map>
//#include<bits/stdc++.h>
using namespace std;

#define sfi(i) scanf("%d",&i)
#define sfs(i) scanf("%s",(i))
#define pri(i) printf("%d\n",i)
#define sff(i) scanf("%lf",&i)
#define ll long long
#define ull unsigned long long
#define mem(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define eps 1e-10
#define PI acos(-1.0)
#define lowbit(x) ((x)&(-x))
#define zero(x) (((x)>0?(x):-(x))<eps)
#define fl() printf("flag\n")
#define MOD(x) ((x%mod)+mod)%mod
#define endl '\n'
#define pb push_back
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)

const int maxn=1e5+9;
const int maxm=4e5+9;

ll quick_mod(ll a,ll b,ll m)
{
    ll ans=1;
    a%=m;
    while(b)
    {
        if(b&1) ans=ans*a%m;
        b>>=1;
        a=a*a%m;
    }
    return ans;
}

int main()
{
    //FAST_IO;
    //freopen("input.txt","r",stdin);

    int n;
    int a,b,c;
    cin>>a>>b>>c>>n;
    int ans=0;
    for(int i=0;i<=a;i++)
    {
        for(int j=0;j<=b;j++)
        {
            int k=n-i*500-j*100;
            if(k>=0&&k%50==0&&k/50<=c)
            {
                //cout<<i<<j<<endl;;
                ans++;
            }


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


Measured memory_bytes: 256
use proconio::input;

fn main() {
	input!(a: usize);
	input!(b: usize);

	if a==b {
		println!("Draw");
		return;
	}
	if a==1 {
		println!("Alice");
		return;
	}
	if b==1 {
		println!("Bob");
		return;
	}
	if a>b {
		println!("Alice");
		return;
	}
	println!("Bob");
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
  int data[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin >> k;
  cout << data[k - 1] << endl;
  return 0;
}

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

#include <cmath>

using namespace std;



int main(){
    cout << setprecision(20) << fixed;

    while (true) {
        long long int a, b;
        string        op;
        cin >> a >> op >> b;

        if (op == "+") cout << a + b << "\n";
        else if (op == "-") cout << a - b << "\n";
        else if (op == "*") cout << a * b << "\n";
        else if (op == "/") cout << a / b << "\n";
        else return 0;
    }
}



Measured memory_bytes: 3140
let rec enum_downto_fold a b v f =
  if a < b then v else enum_downto_fold (a-1) b (f v a) f

let () =
  Scanf.scanf "%d %d" @@ fun n k ->
  let a = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  enum_downto_fold 40 0 (0, min_int) (fun (sa, sb) i ->
    let b = 1 lsl i in
    let v0, v1 = Array.fold_left (fun (v0,v1) ai ->
      v0 + (ai land b), v1 + (ai lxor b) land b) (0, 0) a
    in
    if k land (1 lsl i) = 0 then
      sa + v0, sb + max v0 v1
    else begin
      sa + v1, max (sa + v0) (sb + max v0 v1)
    end)
  |> fun (sa,sb) -> Printf.printf "%d\n" (max sa sb)

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)

typedef long long ll;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> sum(n + 1, 0);
  map<int, int> cnt_map;

  FOR(i, 1, n + 1) {
    int value;
    cin >> value;
    value += sum[i - 1];
    sum[i] = value % k;
  }
  ll cnt = 0;
  FOR(i, 0, n + 1) {
    if (i >= k) {
      int prev_i = i - k;
      int prev_value = (sum[prev_i] + k - prev_i % k) % k;
      cnt_map[prev_value]--;
    }
    int value = (sum[i] + k - i % k) % k;
    cnt += cnt_map[value];
    cnt_map[value]++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 10368
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cstdio>
#include<cmath>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
int MOD=1000000007;
struct Node{
  int no;
  int par;
  bool comp;
  vector<Node*> child;
  void build(int i){
    no=i;par=i;comp=true;
  }
};
signed main(){
    int n;cin>>n;
    vector<int> a(n);
    vector<Node> node(n+1);
    rep(i,n+1){
        node[i].build(i);
    }
    rep(i,n){
        cin>>a[i];
        node[i+1].child.push_back(&node[a[i]]);
    }
    bool flag=true;
    int res=0;
    queue<Node> que;
    que.push(node[1]);
    while(que.front().no!=2){
        ++res;
        Node buf=que.front();que.pop();
        if(buf.comp){
            node[buf.no].comp=false;
        }
        else{
            flag=false;
            break;
        }
        que.push(*buf.child[0]);
    }
	if(flag){
        cout<<res<<endl;
    }
    else{
        cout<<"-1"<<endl;
    }
    return 0;
}

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

typedef long long ll;

int s(int N) {
  int s = 0;
  while (N > 0) {
    s += N % 10;
    N /= 10;
  }
  return s;
}

int main() {
  ll N;
  cin >> N;

  if(N % s(N) == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

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

int max(int a, int b){
  return a >= b ? a : b;
}
int min(int a, int b){
  return b >= a ? a : b;
}
int factorial(int n) {
    if (n > 0) return n*factorial(n - 1);
		else return 1;
}
int compare_up_int(const void *a, const void *b){
   return *(int*)a - *(int*)b;
}
int compare_down_int(const void *a, const void *b){
   return *(int*)b - *(int*)a;
}
int euclid(int a, int b){
  if(a < b){int tmp = a;a = b;b = tmp;}
  int r = a % b;
  if(r < 0) r += b;
  while(r != 0){
    a = b;b = r;r = a % b;
    if(r < 0) r += b;
  }
  return b;
}

int main(){
  int H,W;
  scanf("%d %d",&H,&W);
  char a[H][W];
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      scanf("%1s",&a[i][j]);
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(a[i][j] == '#'){
        if(i-1<0)i=1;
        if(j-1<0)j=1;
        if(i+1>H-1)i=H-1;
        if(j+1>W-1)j=W-1;
        if(a[i-1][j] == '.' && a[i+1][j] == '.' && a[i][j-1] == '.' && a[i][j+1] == '.'){
          printf("No\n");
          return 0;
        }
      }
    }
  }
  //printf("%c",a[0][0]);
  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 128
use std::io::{stdin, Read, StdinLock};
use std::str::*;
use std::cmp;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main(){
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    while let Some(s) = sc.read1::<i64>() {
        let c: i64 = sc.read();

        // (s, c) -> (s + a, c - 2a) -> min(s + a, (c - 2a) // 2)
        // s + a = (c - 2a) // 2 <=> a = c/4 - s/2
        let mut res: i64 = 0;
        for b in -10..10 {
            let mut a = c / 4 - s / 2 + b;
            a = cmp::max(a, 0);
            a = cmp::min(a, c / 2);
            let cand = cmp::min(s + a, (c - 2 * a) / 2);
            res = cmp::max(res, cand);
        }
        println!("{}", res);
    }
}


Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		int n, k;
		int[] stock;
		int[] needs;
		StringTokenizer st;
		StringBuilder sb = new StringBuilder();

		next: while ((line = br.readLine()) != null && !line.isEmpty()) {

			n = Integer.parseInt(line.substring(0, line.indexOf(' ')));
			k = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
			if (n == 0 && k == 0) {
				break;
			}
			stock = new int[k];
			needs = new int[k];

			st = new StringTokenizer(br.readLine());
			for (int i = 0; i < k; i++) {
				stock[i] = Integer.parseInt(st.nextToken());
			}
			for (int i = 0; i < n; i++) {
				st = new StringTokenizer(br.readLine());
				for (int j = 0; j < k; j++) {
					needs[j] += Integer.parseInt(st.nextToken());
				}
			}
			for (int i = 0; i < k; i++) {
				if (stock[i] < needs[i]) {
					sb.append("No" + '\n');
					continue next;
				}
			}
			sb.append("Yes" + '\n');
		}
		System.out.print(sb.toString());
	}
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll L,R;
ll i,j,k,ans;
int main(){
    scanf("%lld%lld", &L,&R);
    if(R+1-L>=2019){
        printf("0");
    }else{
        ans = 2018;
        fornum(i,L,R+1){
            fornum(j,i+1,R+1){
                if(i*j%2019<ans){
                    ans = i * j % 2019;
                }
            }
        }
        printf("%lld", ans);
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
const int MAX_N = 100010;

int N;
vector<int> h;

int dp[MAX_N];

void _main()
{
    cin >> N;
    h.resize(N);
    rep(i, 0, N) cin >> h[i];
    rep(i, 0, N + 1) dp[i] = inf;
    dp[0] = 0;
    rep(i, 0, N)
    {
        if (i - 1 >= 0) chmin(dp[i], dp[i - 1] + abs(h[i - 1] - h[i]));
        if (i - 2 >= 0) chmin(dp[i], dp[i - 2] + abs(h[i - 2] - h[i]));
    }
    cout << dp[N - 1] << endl;
}


Measured memory_bytes: 1024
from collections import deque

n = int(input())
a_li = list(map(int, input().split()))
b_li = deque()
for i in range(len(a_li)):
    if i % 2 == 0:
        b_li.append(a_li[i])
    else:
        b_li.appendleft(a_li[i])

if len(a_li) % 2 == 0:
    print(*b_li)
else:
    print(*list(b_li)[::-1])


Measured memory_bytes: 107292
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long int n1,n2,cnt=1; cin>>n1>>n2;
	long long int n=__gcd(n1,n2); 
	for(long long i=2;i*i<=n;i++) {
		if(n%i==0) {
			cnt++;
			while(n%i==0) n/=i;
		}
	}
	
	if(n>1) cnt++;
	cout<<cnt<<endl;
	
	return 0;
}


Measured memory_bytes: 256
from collections import deque

def linear():
    # データを格納
    s = deque()
    t = deque()
    n = int(input())
    s_list = list(map(int, input().split()))
    q = int(input())
    t_list = list(map(int, input().split()))
    for i in s_list:
        s.append(i)
    for i in t_list:
        t.append(i)

    # tがsに存在するか検索
    count = 0
    for i in t:
        f = True
        while True:
            try:
                s.remove(i)
                if f:
                    count += 1
                    f = False
            except ValueError:
                break
    print(count)

if __name__ == "__main__":
    linear()


Measured memory_bytes: 7012
import java.util.Scanner;

class Main
{
  public static void main(String[] args)
  {
	  int l,w;
	  boolean t=true;
	  Scanner in=new Scanner(System.in);
	  
	  while(t)
      { l=in.nextInt();
	    w=in.nextInt();
		
		if(l==0 && w==0)
		{   
	        
			break;
		}
		
        for(int i=0;i<l;i++)
        {
		    for(int j=0;j<w;j++)
		    {
			    System.out.print("#");
		    }
		    System.out.println("");
	    }
		System.out.println("");
		
	  }		
	  

    
  }

}

Measured memory_bytes: 33056
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int tino,tiya,kokoa,rize,syaro;
    cin>>tino>>tiya>>kokoa>>rize>>syaro;
    int gotiusa=0,aoyama=0;
    for(;tiya>0;gotiusa++)tiya-=rize;
    for(;kokoa>0;aoyama++)kokoa-=syaro;
    cout<<tino-max(aoyama,gotiusa)<<endl;
}

Measured memory_bytes: 3116
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
	int f=1;char k=getchar();x=0;
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=x*10+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x>=10) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int k,int mod){
	int res=1,bas=x;
	while(k){
		if(k&1) res=1ll*res*bas%mod;
		bas=1ll*bas*bas%mod,k>>=1;
	}
	return res;
}
const int N = 1e5+5;
int n,m,l,r,ans,c[N];
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n),read(m);
	for(ri i=1;i<=m;++i){
		read(l),read(r);
		++c[l],--c[r+1];
	}
	for(ri i=1;i<=n;++i) c[i]+=c[i-1],ans+=c[i]==m;
	print(ans);
	return 0;
}

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

void fst()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
}

                                                                                                                                                                                       

int32_t main()
{
    string s,t;
    cin>>s>>t;
    int cnt=0;
    for(int i=0;i<s.size();i++){
        if(s[i]!=t[i]){
            cnt++;
        }
    }
    cout<<cnt;
}


Measured memory_bytes: 3896
n,y=map(int,input().split())

p=[]

for i in range(n+1):
    for j in range(n+1-i):
        if 10000*i+5000*j+1000*(n-i-j)==y:
            p.append([i,j,n-i-j])

if p==[]:
    print("-1 -1 -1")
else:
    print(p[0][0],p[0][1],p[0][2])
    

Measured memory_bytes: 3060
N = int(input())
H = list(map(int, input().split()))
ans = 0

for i in range(100):
	prev = 0
	for j,h in enumerate(H):
		if prev == 0 and h != 0:
			ans+=1
		prev = h
		if h != 0:
			H[j]-=1
	if sum(H) == 0:
		break

print(ans)

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

int main(){
  int cs, ts;

  cin >> cs;

  int *c = new int[cs + 1];

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


  cin >> ts;
  int t , cnt = 0;

  for(int i = 0; i < ts; i++){
    cin >> t;
    c[cs] = t;
    int j = 0;
    while(t != c[j]){
      j++;
      if(j == cs){
        cnt--;
      }
    }
    cnt++;
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
int n,m;
char grid[1200][1200];
queue<pair<pair<int,int>,int> > q; 
bool blk[1200][1200];
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		scanf("%s",grid[i]+1);
		for(int j=1;j<=m;j++){
			if(grid[i][j]=='#'){
				q.push(make_pair(make_pair(i,j),0));
				blk[i][j]=1;
			}
		}
	}
	while(!q.empty()){
		int stp=q.front().second;
		pair<int,int> pos=q.front().first;
		q.pop();
		for(int i=0;i<4;i++){
			int nx=pos.first+dx[i];
			int ny=pos.second+dy[i];
			if(nx>=1&&nx<=n&&ny>=1&&ny<=m){
				if(!blk[nx][ny]){
					q.push(make_pair(make_pair(nx,ny),stp+1));
					blk[nx][ny]=1;
				}
			}
		}
		if(q.empty())
		{
			cout<<stp<<endl;
			return 0; 
		}
	}
	return 0;
}


Measured memory_bytes: 14736
#include<cstdio>
using namespace std;
int main(void){
	int n;
	int i,j;
	int sum;
	int flg;
	scanf("%d",&n);
	flg=0;
	for(i=0;i<=25;i++){
		for(j=0;j<=15;j++){
			sum=4*i+7*j;
			if(sum==n){
				flg=1;
				break;
			}
		}
		if(flg==1)	break;
	}
	if(flg==1)	printf("Yes\n");
	else		printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;

int main(){
  int m1,d1,m2,d2;
  cin>>m1>>d1>>m2>>d2;
  if (m1!=m2){
    cout<<1<<endl;
    
  }else{
    cout<<0<<endl;
  }


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll sum=0, imax=0;
  ll N;
  ll tmp;
  cin >> N;
  REP(i, N){
    cin >> tmp;
    sum += tmp;
    imax = max(imax, tmp);
  }

  if(2*imax<sum){
    cout << "Yes" << "\n";
  }else{
    cout << "No" << "\n";
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;


long long solve(long long a, long long b)
{
    if (a == 0 || b == 0)
        return 0;
    if (a == b)
        return a + b;
    if (a < b)
        return a + b + solve(b - a, a);
    
    long long k = a / b;
    return 2 * k * b + solve(a - k * b, b);
}


int main(int,  char **)
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    long long n, x;
    scanf("%lld%lld", &n, &x);

    long long ans = x + solve(x, n - x);
    printf("%lld\n", ans);


	return 0;
}




Measured memory_bytes: 256
//nani?
//omo ta tori da
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
#define pi acos(-1);
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define f(i,a,b) for( int i = a; i < b ; i++ )
#define sor(a) sort( a.begin(), a.end() )
#define rsor(a) sort( a.rbegin(), a.rend() )
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define inf 1LL<<62
typedef long long ll;
typedef double ld;
using namespace std;
using namespace __gnu_pbds;
//const ll inf=1e10;
const ll MOD=1e9+7;
const ll mod=998244353;
const ll N = 1e7 + 5;
// ac cmtr;
const int MAX_N = 2e5+5;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << endl;}
 
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1<<" | ";
  __f(comma+1, args...);}
#else
#define trace(...)
#endif
//---------------------------

ll dp[2005][2005];
ll cnt[MAX_N];
ll n;
vector <pair <ll,ll > > adj[MAX_N];

void dij(ll a){

    set <pair <ll,ll> > s;
    f(i,0,n+1) {dp[i][a]=inf;}
    s.insert(mp(0,a));
    dp[a][a] = 0;
    //ans[a] = 1;
    while(!s.empty()){
        ll ini  = s.begin()->sc;s.erase(s.begin());
        for(auto xd : adj[ini]){
            if(dp[xd.fs][a] > dp[ini][a] + xd.sc){
                s.erase(mp(dp[xd.fs][a],xd.fs)); 
                //ans[xd.fs] = ans[ini];
                dp[xd.fs][a] = dp[ini][a] + xd.sc;
                s.insert(mp(dp[xd.fs][a],xd.fs));
            }
        }
        
    }
  return;
}

int main(){
    fastio;
    ll x,y;
    cin>>n>>x>>y;
    f(i,1,n){
        adj[i].pb({i+1,1});
        adj[i+1].pb({i,1});
    }
    adj[x].pb({y,1});
    adj[y].pb({x,1});
    f(i,1,n+1){
        dij(i);
    }
    f(i,1,n+1){
        for(int j=1;j<=n;j++){
            cnt[dp[i][j]]++;
        }
    }
    f(i,1,n){
        cout<<cnt[i]/2<<" "<<endl;
    }


   
}

Measured memory_bytes: 38016
#include <stdio.h>
#include <stdlib.h>

typedef struct	s_bingo
{
  	int	n;
  	int	mark;
}				t_bingo;

int		main(void)
{
  	int	i;
  	int	j;
  	int	k;
  	int	N;
  	int	b;
  	int num;
  	t_bingo	a[3][3];
  
  	for (i = 0; i < 3; i++)
    {
		num = scanf("%d %d %d", &a[i][0].n, &a[i][1].n, &a[i][2].n);
  		if (num != 3)
          	return (0);
      	a[i][0].mark = 0;
      	a[i][1].mark = 0;
      	a[i][2].mark = 0;
    }
  
  	num = scanf("%d", &N);
  	if (num != 1)
      	return (0);
  
  	for (k = 0; k < N; k++)
    {
      	num = scanf("%d", &b);
      	for (i = 0; i < 3; i++)
          	for (j = 0; j < 3; j++)
              	if (a[i][j].n == b)
                  	a[i][j].mark = 1;
    }
  
  	if (a[0][0].mark && a[0][1].mark && a[0][2].mark)
      	printf("Yes");
  	else if (a[1][0].mark && a[1][1].mark && a[1][2].mark)
      	printf("Yes");
  	else if (a[2][0].mark && a[2][1].mark && a[2][2].mark)
      	printf("Yes");
  	else if (a[0][0].mark && a[1][0].mark && a[2][0].mark)
      	printf("Yes");
  	else if (a[0][1].mark && a[1][1].mark && a[2][1].mark)
      	printf("Yes");
  	else if (a[0][2].mark && a[1][2].mark && a[2][2].mark)
      	printf("Yes");
  	else if (a[0][0].mark && a[1][1].mark && a[2][2].mark)
      	printf("Yes");
  	else if (a[0][2].mark && a[1][1].mark && a[2][0].mark)
      	printf("Yes");
  	else
      	printf("No");
  
  	return (0);
}

Measured memory_bytes: 128
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

N = int(input())
S = input()

acc_w = [0] * (N + 1)
acc_b = [0] * (N + 1)
for i in range(1, N + 1):
    c = S[i - 1]
    acc_w[i] = acc_w[i - 1] + (1 if c == '.' else 0)
    acc_b[i] = acc_b[i - 1] + (1 if c == '#' else 0)

ans = INF
for i in range(N + 1):
    now = acc_b[i] + acc_w[-1] - acc_w[i]
    ans = min(ans, now)
print(ans)






Measured memory_bytes: 25140
#include <bits/stdc++.h>
#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
#define ll long long
using namespace std;

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

	ll n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	ll ans = 0;
	for(int i = 0; i < n; ++i) {
		for(int j = i+1; j < n; ++j) {
			ll s = a[i]+a[j];
			int idx = lower_bound(a.begin(), a.end(), s) - a.begin();
			if(idx == n || a[idx] >= s) --idx;
			ans += (idx - j);
		}
	}
	cout << ans;
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int n; cin >> n;
  string s; cin >> s;
  int ans=0;
  rep(i,1000){
    int c[]={i/100,(i/10)%10,i%10};
    int id=0;
    rep(j,n){
      if(s[j]-'0'==c[id]) id++;
      if(id==3) break; //忘れがち
    }
    if(id==3) ans++;
      
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 384
import math
m,n=map(int,input().split())
k=int(math.sqrt(n))
ju=[False for i in range(k+1)]
da=[]
ki=2
co=-1
while ki<k+1:
	if n%ki==0:
		n//=ki
		if ju[ki]:
			da[co]+=1
		else:
			co+=1
			da.append(1)
			ju[ki]=True
	else:
		ki+=1
co+=1
ans=1
for i in range(co):
	si=da[i]
	dp=[[0 for i in range(si+1)] for j in range(m+1)]
	dp[0][0]=1
	for j in range(1,m+1):
		for k in range(si+1):
			for l in range(k+1):
				dp[j][k]=(dp[j-1][l]+dp[j][k])%(1000000007)
	ans=(ans*dp[m][si])%(1000000007)
if n>1:
	ans=((ans*m)%1000000007)
print(ans)


Measured memory_bytes: 122716
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool prime(ll n) {
  if (n == 1) {
    return false;
  } else {
    for (ll i = 2; i <= (ll)pow(n, 0.5); i++) {
      if (n%i == 0) return false;
    }
  }
  return true;
}
ll RepeatSquaring(ll n, ll p, ll m) {
  if (p == 0) return 1;
  if (p%2 == 0) {
    ll t = RepeatSquaring(n, p/2, m);
    return (t*t)%m;
  }
  return (n*RepeatSquaring(n, p-1, m))%m;
}

int main() {
  ll n, m;
  cin >> n;
  vector <ll> v(n);
  rep(i, n) cin >> v.at(i);
  cin >> m;
  rep(i, m) {
    ll a;
    cin >> a;
    cout << distance(v.begin(), lower_bound(v.begin(), v.end(), a)) << endl;
  }
}


Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<set>
#include<regex>
#include<ctype.h>
using namespace std;

int main(void) {
	
	int n, l[10], max_n = 0, ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> l[i];
		max_n = max(max_n, l[i]);
		ans += l[i];
	}

	cout << (max_n < ans - max_n ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;



int main() {
string s;
cin>>s;
int count=0;
rep(i,3) if(s[i]=='1')count++;
cout<<count<<endl;



return 0;
}

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

#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, n, m) for(ll (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
//constexpr ll INF = 1LL<<61;

constexpr ll mod = 1e9+7;

double A, B, N;
ll cal(ll x){
  return ll(floor(A*x/B) - A*floor(x/B));
}

int main(){
  cin >> A >> B >> N;
  ll ans = max(cal(min(B-1, N)), cal(N));
  ans = max(ans, cal(min(B, N)));
  FOR(i, (ll)B, (ll)min(B+A+1, N+1)){
    ans = max(ans, cal(i));
  }
  // FOR(i, ll(max(0, (ll)N-A)), (ll)N){
  //   ans = max(ans, cal(i));
  // }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3720
#include <iostream>
#include <string>
#include <sstream>
#include <cassert>


int permutation(int *a, int n) {
	bool *b = new bool[n];
	for (int i=0;i<n;++i){
		b[i] = false;
	}
	int sign = 1;
	for (int i=0;i<n;++i) {
		int local_sign = 1;
		int j = i;
		while (!b[j]) {
			b[j] = true;
			j = a[j];
			if (b[j]) {
				break;
			}
			local_sign *= -1;
		}
		sign *= local_sign;
	}
	delete [] b;
	return sign;
}

int main() {
	int n;
	{
		std::string buf;
		std::getline(std::cin, buf);
		std::istringstream iss(buf);
		iss >> n;
	}
	int* a1 = new int[n];
	{
		std::string buf;
		std::getline(std::cin, buf);
		std::istringstream iss(buf);
		for (int i=0;i<n;++i) {
			int xx;
			iss >> xx;
			a1[i] = xx;
		}
	}
	int* a2 = new int[n];
	{
		std::string buf;
		std::getline(std::cin, buf);
		std::istringstream iss(buf);
		for (int i=0;i<n;++i) {
			int xx;
			iss >> xx;
			a2[i] = xx;
		}
	}
	int* a3 = new int[n];
	{
		std::string buf;
		std::getline(std::cin, buf);
		std::istringstream iss(buf);
		for (int i=0;i<n;++i) {
			int xx;
			iss >> xx;
			a3[i] = xx;
		}
	}
	int *a = new int [n];
	for (int i=0;i<n;++i) {
		if (a1[i] < a3[i]) {
			if (a3[i] != a1[i]+2 || a2[i] != a1[i]+1) {
				std::cout << "No" << std::endl;
				return 0;
			}
			a[i] = a1[i] / 3 + 1;
		} else {
			if (a1[i] != a3[i]+2 || a2[i] != a3[i]+1) {
				std::cout << "No" << std::endl;
				return 0;
			}
			a[i] = - (a3[i] / 3 + 1);
		}
	}
	int *evens = new int[n/2];
	int *odds = new int[n/2 + n%2];
	int even_sign = 1;
	int odd_sign = 1;
	for (int i = 0; i < n; ++i) {
		if (i%2 == 0) {
			if (a[i]%2 == 0) {
				std::cout << "No" << std::endl;
				return 0;
			}
			if (a[i] > 0) {
				odds[i/2] = a[i]/2;
			} else {
				odds[i/2] = -a[i]/2;
				odd_sign *= -1;
			}
		} else {
			if (a[i]%2 == 1) {
				std::cout << "No" << std::endl;
				return 0;
			}
			if (a[i] > 0) {
				evens[i/2] = a[i]/2 - 1;
			} else {
				evens[i/2] = -a[i]/2 - 1;
				even_sign *= -1;
			}
		}
	}
	if (permutation(odds, n/2 +n%2) * even_sign == 1 and permutation(evens, n/2) * odd_sign == 1) {
		std::cout << "Yes" << std::endl;
	} else {
		std::cout << "No" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3180
#include"bits/stdc++.h"
using namespace std;

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

const double PI = acos(-1.0);
const int MOD = pow(10, 9) + 7;

#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define all(v) v.begin(), v.end()

ll modinv(ll a, ll m) {
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

inline void finish() {
	cout << -1 << endl;
	exit(0);
}

template <typename T>
inline void debug(vector<T> v) {
	cout << "[";
	for (size_t i = 0; i < v.size() - 1; ++i) {
		cout << v[i] << ", ";
	}
	cout << v[v.size() - 1] << "]" << endl;
}

class Point {
public:
	double x, y;
	Point(double x, double y) {
		this->x = x;
		this->y = y;
	}
	Point() {
		x = 0.0;
		y = 0.0;
	}
};

class Mod {
	static inline ll Add(ll a, ll b) {
		return (a + b) % MOD;
	}

	static inline ll Sub(ll a, ll b) {
		ll ans = (a - b) % MOD;
		return (ans < 0) ? (ans + MOD) : ans;
	}

	static inline ll Mul(ll a, ll b) {
		return (a * b) % MOD;
	}
	
	static inline ll Div(ll a, ll b) {
		return (a % MOD) * modinv(b, MOD) % MOD;
	}
};

inline double distance(Point p1, Point p2) {
	return sqrt(pow(p1.x - p2.x, 2) + pow(p1.y - p2.y, 2));
}

inline int Kaijo(int n) {
	int ans = 1;
	for (int i = 2; i <= n; ++i) {
		ans *= i;
	}
	return ans;
}

void Main();
inline void DebugMain() {
	while (true) {
		Main();
	}
}

int main() {
	bool debug = false;
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	if (debug) {
		cout << "\x1b[41m" << "Debug Mode このまま提出すると死" << endl;
	}
	(debug) ? DebugMain() : Main();
	return 0;
}

inline void Main(){
	int N;
	string S;
	string ans = "";
	cin >> N >> S;
	for (int i = 0; i < S.size(); ++i) {
		char moji = S[i] + N;
		if (moji > 90) {
			moji -= 26;
		}
		ans += moji;
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int> P(N);
  for(int i=0;i<N;i++){
    cin>>P.at(i);
  }
  int count = 0;
  int curMin = 300000;
  for(int i=0;i<N;i++){
    curMin = min(curMin,P.at(i));
    if(curMin==P.at(i)){
      count++;
    }
  }
  cout<<count<<endl;
  return 0;
}


Measured memory_bytes: 1024
// https://atcoder.jp/contests/dp/tasks/dp_i
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;

#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define EPS (1e-7)
#define INF (1e9)
#define MODI (1000000007)

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// dp[i][j] : コインをi枚使い、j枚が表である確率
// double dp[3001][3001];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	// 入力、DP後、DP前
	vector<double> p(n), dpA(n + 1, 0), dpB(n + 1, 0);
	vector<double>* p_dpa = &dpA;
	vector<double>* p_dpb = &dpB;

	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	(*p_dpb)[0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= i; j++) {
			// i-1回目で表の枚数がj-1で、i回目が表
			// i-1回目で表の枚数がjで、i回目が裏
			(*p_dpa)[j] = (*p_dpb)[j - 1] * p[i - 1] + (*p_dpb)[j] * (1.0 - p[i - 1]);
		}
		swap(p_dpb, p_dpa);
	}
	double ans = 0;
	for (int i = n / 2 + 1; i <= n; i++) {
		ans += (*p_dpb)[i];
	}
	printf("%0.10f\n", ans);

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+5;
vector<int> g[100005];  //友人関係
vector<int> vis(N,0);
vector<int> cnt(100005,0);
vector<int> s_cnt(100005,0);
void dfs(int s,int c){
    vis[s]=1;
    cnt[s]=c;
    s_cnt[c]++;
    for(auto i:g[s]){
        if(!vis[i]){
            dfs(i,c);
        }
    }

}
int main(){
    int N,M,K; cin>>N>>M>>K;
    for(int i=0;i<M;i++){
        int u,v; cin>>u>>v;
        g[u].push_back(v);  //友人関係を入れる
        g[v].push_back(u);
    }

    int c=1;
    for(int i=1;i<=N;i++){
        if(!vis[i]){
            dfs(i,c);   //深さ優先
            c++;
        }
    }
    vector<int> sub(100005,0);
    for(int i=0;i<K;i++){
        int u,v; cin>>u>>v; //ブロック関係を入れる
        if(cnt[u]==cnt[v]){
            sub[u]++;sub[v]++;
        }
    }
    for(int i=1;i<=N;i++){
        cout<<s_cnt[cnt[i]]-g[i].size()-1-sub[i];
        cout<<" ";
    }

    return 0;
}

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

int main() {

  int N, D;
  cin >> N >> D;

  vector<vector<int>> X(N,vector<int>(D));

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> X[i][j];
    }
  }

  int answer = 0;

  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      vector<int> y = X[i];
      vector<int> z = X[j];
      int d = 0;
      for (int k = 0; k < D; k++) {
        d += abs(y[k] - z[k]) * abs(y[k] - z[k]);
      }
      double s = (double) sqrt(d);
      if (floor(s) * floor(s) == d) {
        answer++;
      }
    }
  }
  
  cout << answer << endl;

}

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

using namespace std;

typedef long long ll;

int N, C, D[31][31], Cnt[3][31];

int main() {
    cin >> N >> C;
    for (int i = 1; i <= C; i++) {
        for (int j = 1; j <= C; j++) {
            cin >> D[i][j];
        }
    }
    int c;
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            cin >> c;
            Cnt[(i+j) % 3][c]++;
        }
    }

    int res = 1 << 30;
    for (int c0 = 1; c0 <= C; c0++) {
            for (int c1 = 1; c1 <= C; c1++) {
                if (c0 == c1) { continue; }
                    for (int c2 = 1; c2 <= C; c2++) {
                        if (c0 == c2 || c1 == c2) { continue; }

                        int tmp = 0;
                        for (int c = 1; c <= C; c++) {
                            tmp += Cnt[0][c] * D[c][c0];
                            tmp += Cnt[1][c] * D[c][c1];
                            tmp += Cnt[2][c] * D[c][c2];
                        }
                        res = min(res, tmp);
                    }
            }
    }

    cout << res << endl;
}

/*
int main() {
    int N, C, D[300001], Co[300001];
    cin >> N >> C;
    for (int i = 1; i <= C; i++) {
        for (int j = 1; j <= C; j++) {
            cin >> D[i*C + j];
        }
    }
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            cin >> Co[i*N + j];
        }
    }

    ll D0[31], D1[31], D2[31];

    for (int c = 1; c <= C; c++) {
        ll ds[3] = { 0, 0, 0 };

        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= N; j++) {
                int orig = Co[i * N + j];
                ll d = D[orig * C + c];
                ds[(i + j) % 3] += d;
            }
        }

        D0[c] = ds[0];
        D1[c] = ds[1];
        D2[c] = ds[2];
    }

    ll ddd = 99999999999999;
    for (int i = 1; i <= C; i++) {
        for (int j = 1; j <= C; j++) {
            if (i == j) { continue; }
            for (int k = 1; k <= C; k++) {
                if (i == k || j == k) { continue; }

                ddd = min(ddd, (ll)(D0[i] + D1[j] + D2[k]));
            }
        }
    }

    cout << ddd<< endl;
}
*/

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

def is_power(a, b):
  while a % b == 0:
    a = a / b
  if a == 1:
    return True
  return False

def is_perfect_power(n):
    for i in range(n//2, 1, -1):
        if is_power(n, i):
            return True
    return False

ans = 1

for i in range(x, 1, -1):
    if is_perfect_power(i):
        ans = i
        break

print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	
	static int[] par=new int[1001];
	static void init(int n) {
		for(int i=0; i<=n; i++) {
			par[i]=i;
		}
	}
	
	static int root(int x) {
		if(par[x]==x) return x;
		return par[x]=root(par[x]);
	}
	
	static void unite(int x, int y) {
		par[root(x)]=root(y);
	}
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			int[] F=new int[1001];
			for(int i=2; i<=1000; i++) {
				F[0]=1;
				F[1]=2;
				F[i]=F[i-2]+F[i-1];
				F[i]%=1001;
			}
			while(sc.hasNext()) {
				int V=sc.nextInt();
				int d=sc.nextInt();
				init(V);
				for(int i=1; i<=V; i++) {
					for(int j=i+1; j<=V; j++) {
						if(Math.abs(F[j]-F[i])<d) {
							unite(i, j);
						}
					}
				}
				int count=0;
				for(int i=1; i<=V; i++) {
					if(par[i]==i) {
						count++;
					}
				}
				System.out.println(count);
			}
			
			
			
		}
	}
}


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int N,a,b,c;
int l[33];

int search( ll bit, int leng ){
    ll hit = 0;
    ll mask = leng == a ? 3 : leng == b ? 2 : 1;
    int value = -10;
    int i = 0;
    while( bit ){
        hit = bit & 0x3;
        if( hit == mask ){
            leng -= l[i];
            value += 10;
        }
        bit >>= 2;
        i++;
    }
    if( value == -10 ) return 1e6;
    return value + abs(leng);
}

int main() {

    Scd(N);
    Scd3(a,b,c);
    Rep(i,N) Scd(l[i]);

    int ans = INF;
    for( ll i = 0; i < 1<<N*2; i++ ){
        int tmp =
        search( i , a )+
        search( i , b )+
        search( i , c );
        ans = min(tmp,ans);
    }
    printf ("%d\n", ans);

    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
void saiki(int nn,int mm);
int n,s;
int box[10];
int sum,cnt;
int main(void){
	int i;
	for(i=0;i<=9;i++){
		box[i]=i;
	}
	while(1){
		scanf("%d %d",&n,&s);
		if(n==0&&s==0){
			break;
		}
		sum=0;
		cnt=0;
		saiki(0,0);
		printf("%d\n",cnt);
	}
	return 0;
}
void saiki(int nn,int mm){
	if(mm==n){
		if(sum==s){
			cnt++;
		}
	}
	else{
		if(nn<=9){
			sum+=box[nn];
			saiki(nn+1,mm+1);
			sum-=box[nn];
			saiki(nn+1,mm);
		}
	}
}


Measured memory_bytes: 2048
#include <iostream>
#include <sstream>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <stdexcept>
#include <algorithm>
#include <set>
#include <map>
#include <stdlib.h>
using namespace std;
int main(){
    // + = 0 - = 1 とする
    int A,B,C,D,a,b,c,p,q;
    char aa,bb,cc;
    cin >> p;
    D = p % 10;
    p /= 10;
    C = p % 10;
    p /= 10;
    B = p % 10;
    p /= 10;
    A = p % 10;
    p /= 10;
    q = 0;
    for(a = 0;a < 2;a++){
        for(b = 0;b < 2;b++){
            for(c = 0;c < 2;c++){
                p = A;
                if(a == 0){
                    p += B;
                    aa = '+';
                }
                else{
                    p -= B;
                    aa = '-';
                }
                if (b == 0){
                    p += C;
                    bb = '+';
                }
                else{
                    p -= C;
                    bb = '-';
                }
                if (c == 0){
                    p += D;
                    cc = '+';
                }
                else{
                    p -= D;
                    cc = '-';
                }
                if(p == 7){
                    cout << A << aa << B << bb << C << cc << D << "=7" << endl;
                    q = 1;
                    break;
                }
            }
            if (q == 1){
                break;
            }
        }
        if (q == 1){
            break;
        }
    }
    
}

Measured memory_bytes: 3600
my $N = <STDIN>;
chomp($N);
my $tmp = <STDIN>;
chomp($tmp);

my @t = split(/ /,$tmp);

my $c = 0;

for (1..$#t){
    if($c <= -2){
	$c = 1;
	last;
    }
    elsif($c == -1)
    {
	if($t[$_] < $t[$_-1]){
	    $c = 1;
	    last;
	}
	else{
	    $c += $t[$_]-$t[$_-1];
	    $c = $c > 0 ? 0 : $c;
	}
    }
    else{
	$c += $t[$_]-$t[$_-1];
	$c = $c > 0 ? 0 : $c;
    }
}

if($c == 1 || $c <= -2){print "No\n";}
else{print "Yes\n";}

1;


Measured memory_bytes: 17228
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long __int64;

__int64 comb[65][65];
int sm[]={-1,0};

string calc(int n, int l, __int64 r)
{
	string ret;
	if(n==0) return (l==0?"0":"1");
	
	if(comb[l][n] < r)
	{
		ret = calc(n-1, l-1, r-comb[l][n]);
		ret += "1";
	}
	else
	{
		ret = calc(n-1, l, r);
		ret += "0";
	}
	
	return ret;
}

int main()
{
	memset(comb,0,sizeof(comb));
	comb[0][0]=1;
	for(int i=1; i<=60; i++)
	for(int j=0; j<=i; j++)
	{
		__int64 sum=0;
		for(int k=0; k<2; k++)
		{
			int p=j+sm[k];
			if(p<0) continue;
			sum += comb[p][i-1];
		}
		
		comb[j][i]=sum;
	}
	
	int N;
	__int64 M;
	while(cin >> N >> M,(N||M))
	{
		__int64 sum=0;
		int R=0;
		for(;; R++)
		{
			if(sum + comb[R][N] >= M) 
			{
				M -= sum;
				break;
			}
			sum += comb[R][N];
		}
		
		string ans =calc(N-1,R,M);
		
		reverse(ans.begin(), ans.end());
		cout << ans << endl;
	}
}

Measured memory_bytes: 0