akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std ;

const int MAX = 110 , MAX2 = 1e5 + 10 ;
const long long inf = 1e17 ;
long long dp[MAX][MAX2] ;
long long arr[MAX] , arr2[MAX] ;
long long n , w ;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    memset(dp , -1 , sizeof(dp));
    cin>>n>>w ;
    long long sum = 0 ;
    for(int i = 0 ; i < n ; ++i)
    {
        cin>>arr[i]>>arr2[i] ;
        sum += arr2[i] ;
    }
    for(int i = 0 ; i < n ; ++i)
    {
        for(int j = 0 ; j <= sum ; ++j)
            dp[i][j] = inf ;
    }
    for(int i = 0 ; i < n ; ++i)
        dp[i][arr2[i]] = arr[i] , dp[i][0] = 0;
    for(int i = 1 ; i < n ; ++i)
    {
        for(int j = 1 ; j <= sum ; ++j)
        {
            dp[i][j] = min(dp[i][j] , dp[i-1][j]);
            if(dp[i-1][j] != inf)
            {
                dp[i][j+arr2[i]] = min(dp[i][j + arr2[i]] , dp[i-1][j] + arr[i]);
            }
        }
    }
    long long ans = 0 ;
    for(int i = 0 ; i < n ; ++i)
    {
        for(int j = 0 ; j <= sum ; ++j)
        {
            if(dp[i][j] <= w)
                ans = max(ans , j*1ll) ;
        }
    }
    return cout<<ans<<"\n" , 0 ;
}


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

int main() {
  int n;
  cin >> n;
  double a[n],res;
  for(int i=0;i<n;i++)cin >> a[i];
  sort(a,a+n);
  res = a[0];
  for(int i=1;i<n;i++)res=(res+a[i])*0.5;
  cout<<std::fixed<<std::setprecision(10)<< res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int A,B,C,K;
  cin>>A;
  cin>>B;
  cin>>C;
  cin>>K;
  int sum=0;
 
  if(K<=(A+B))
  {
   	if(K>=A)
      sum=A;
    else
    {
      sum=K;
    }
  }
  else
  {
    if(K>A+B)
    {
      sum=A;
      K=K-(A+B);
      while(K)
      {
        sum--;
        K--;
      }
    }
  }
   cout<<sum; 
  
 return 0;
}

Measured memory_bytes: 3580
#include <cstring>
#include<cstdio>
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int c,x,k;
	cin>>c;
	x=c*800;
	k=(c/15)*200;
	x=x-k;
	cout<<x;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
using namespace std;
//整形Shift + alt + f　2回
//int x[101],y[101],h[101];
//int koya[100001][];
/*
//ユークリッドの互除法
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
*/
int n;
int res = 0;
int dig;

//int b = {7, 5, 3};

unsigned GetDigit(unsigned num)
{
    unsigned digit = 0;
    while (num != 0)
    {
        num /= 10;
        digit++;
    }
    return digit;
}

void solve(int d, int tmp, int stop)
{
    if (d == stop + 1)
    {
        int flag7 = 0, flag5 = 0, flag3 = 0;
        string s;
        s = to_string(tmp);
        //cout << tmp << endl;
        for (int i = 0; i < s.length(); i++)
        {
            if (s[i] == '7')
            {
                flag7 = 1;
            }
            if (s[i] == '5')
            {
                flag5 = 1;
            }
            if (s[i] == '3')
            {
                flag3 = 1;
            }
        }
        if (tmp <= n && (flag7 == 1) && (flag5 == 1) && (flag3 == 1))
        {
            //cout << tmp << endl;
            res++;
        }
        return;
    }

    int l = 1;
    for (int i = 1; i < d; i++)
        l = l * 10;

    solve(d + 1, tmp + 7 * l, stop);
    solve(d + 1, tmp + 5 * l, stop);
    solve(d + 1, tmp + 3 * l, stop);

    return;
}

int main()
{
    cin >> n;
    dig = GetDigit(n);

    //cout << dig << endl;

    if (dig < 3)
    {
        cout << 0;
        return 0;
    }

    for (int i = 3; i <= dig; i++)
    {
        solve(1, 0, i);
    }
    cout << res;
    return 0;
}


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

namespace AtCoder
{
    class Program
    {

        static void Main()
        {
            //ここから
            string S = ReadLineToString();

            int sum = S.Length;

            long wSum = 0;
            long ans = 0;

            for(int i = 0; i < sum; i++)
            {
                if (S[sum - i - 1] == 'W')
                {
                    wSum++;
                }
                else
                {
                    ans += wSum;
                }
            }
            

            //ここまで

            Console.WriteLine(ans);
            Console.ReadKey();
        }


        static public void Swap<T>(ref T a,ref T b) { T temp = a;a = b;b = temp; }
        static public long GCD(int a, int b){ return b != 0 ? GCD(b, a % b) : a;}
        static public long LCM(int a, int b){ return (long)a * b / GCD(a, b); }



        
        static public string ReadLineToString(){return Console.ReadLine();}
        static public int ReadLineToInt(){return int.Parse(Console.ReadLine());}
        static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); }
        static public string[] ReadLineToStringArray(){return Console.ReadLine().Split(' ').ToArray();}
        static public int[] ReadLineToIntArray(){return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();}
        static public long[] ReadLineToLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public List<string> ReadLineToStringList(){return Console.ReadLine().Split(' ').ToList();}
        static public List<int> ReadLineToIntList(){return Console.ReadLine().Split(' ').Select(int.Parse).ToList();}
        static public List<long> ReadLineToLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }



    }
}


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

using namespace std;
typedef long long Int;

Int n, x, d;
Int appear[108][108];
Int dp[108][108];


bool solve(){
	cin >> n;
	if(n == 0)return false;
	for(Int i = 0;i < 108;i++)
		for(Int j = 0;j < 108;j++)
			appear[i][j] = false;
	for(Int i = 0;i < n;i++){
		cin >> x;
		for(Int j = 0;j < x;j++){
			cin >> d;
			appear[d][i] = true;
		}
	}

	for(Int i = 0;i < n;i++){
		dp[0][i] = 1LL << i;
	}
	for(Int i = 1;i <= 30;i++){
		Int information = 0;
		for(Int j = 0;j < n;j++){
			dp[i][j] = dp[i-1][j];
			if(appear[i][j]){
				information |= dp[i][j];
			}
		}
		for(Int j = 0;j < n;j++){
			if(appear[i][j]){
				dp[i][j] = information;
			}
		}
		if(information == (1LL<<n) - 1){
			cout << i << endl;
			return true;
		}
	}
	cout << -1 << endl;
	return true;
}

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

Measured memory_bytes: 3200
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
D = [int(d) for d in readline().split()]

ans = 0
for i in range(N):
    for j in range(N):
        if j <= i:
            continue
        ans += D[i] * D[j]

print(ans)



Measured memory_bytes: 3060
from collections import Counter
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]
C = Counter(A)
ans = ["No"] * N
ok = Q - K
if ok < 0:
  ans = ["Yes"] * N
  for ANS in ans:
    print(ANS)
  exit()

c = [key - 1 for key,val in C.items() if val > ok]
for i in c:
  ans[i] = "Yes"
for ANS in ans:
  print(ANS)

Measured memory_bytes: 12280
out = []

for _ in range(50):
    m, f, r = map(int, input().split())
    if (m, f, r) == (-1, -1, -1):
        break
    if -1 in (m, f):
        out.append("F")
    elif 80 <= m + f:
        out.append("A")
    elif 65 <= m + f < 80:
        out.append("B")
    elif 50 <= m + f < 65:
        out.append("C")
    elif 30 <= m + f < 50:
        out.append("C" if 50 <= r else "D")
    else:
        out.append("F")

print(*out, sep="\n")


Measured memory_bytes: 5604
#include <stdio.h>

int main()
{
  int N;
  char S[100001];
  int syu[100001];
  int i, k;
int tmp;

  scanf("%d", &N);
  scanf("%s", &S);

  //  1 = S
  // -1 = W
  k = 0;
  while(k < 4) {
    if(k == 0) {
      syu[0] = 1;
      syu[1] = 1;
    } else if(k == 1) {
      syu[0] = 1;
      syu[1] = -1;
    } else if(k == 2) {
      syu[0] = -1;
      syu[1] = 1;
    } else if(k == 3) {
      syu[0] = -1;
      syu[1] = -1;
    }
    if(S[0] == 'o') {
      if(syu[0] == 1) {
	tmp = syu[1];
      } else {
	tmp = -syu[1];
      }
    } else {
      if(syu[0] == 1) {
	tmp = -syu[1];
      } else {
	tmp = syu[1];
      }
    }
    
    for(i = 1; i < N; i++) {
      if(syu[i] == 1) {
	if(S[i] == 'o') {
	  syu[i+1] = syu[i-1];
	} else { //S[i] == 'x'
	  syu[i+1] = -syu[i-1];
	}
      } else { //syu[i] == -1
	if(S[i] == 'o') {
	  syu[i+1] = -syu[i-1];
	} else { //S[i] == 'x'
	  syu[i+1] = syu[i-1];
	}
      }
    }
    
    if(syu[0] == syu[N] && tmp == syu[N-1]) {
      for(i = 0; i < N; i++) {
	if(syu[i] == 1) {
	  printf("S");
	} else {
	  printf("W");
	}
      }
      printf("\n");
      return 0;
    } else {
      k++;
    }
  }
  
  printf("%d\n", -1);
  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;
 
int a[200001],b[200001],c[200001];
int main(){
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int n;
    cin>>n;
    int ans=0;
    rep(i,n) cin>>a[i];
    rep(i,n) cin>>b[i];
    rep(i,29){
        rep(j,n) c[j]=b[j]%(1<<(i+1));
        sort(c,c+n);
        ll t=1<<i;
        ll cnt=0;
        rep(j,n){
            int cur=a[j]%(1<<(i+1));
            cnt+=lower_bound(c,c+n,(t<<1)-cur)-lower_bound(c,c+n,t-cur);
            cnt+=lower_bound(c,c+n,t*4-cur)-lower_bound(c,c+n,t*3-cur);   
        }
        if(cnt%2==1) ans|=(1<<i);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2560
n = input()
n = int(n)
v = input()
li = v.split(" ")
for i in range(n):
	li[i] = int(li[i])

sum_ = []
temp = 0
for i in range(n):
	temp += li[i]
	sum_.append(temp)

sum_ = sorted(sum_)
las = sum_[0]
ct = 1
total = 0

for i in range(1,n):
	if(sum_[i]==las):
		ct += 1
	else:
		if(las==0):
			total += ct + ((ct*(ct-1))/2)
		else:
			total += ((ct*(ct-1))/2)

		ct = 1
		las = sum_[i]

total += ((ct*(ct-1))/2)

if(sum_[n-1]==0):
	print(int(n*(n+1)/2))
else:
	print(int(total))

Measured memory_bytes: 24056
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

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

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

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

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

    let total = (0..N).map(|i| L + i as i64).sum::<i64>();

    let mut min_d = std::i64::MAX;
    let mut best = 0;

    for i in 0..N {
        let apple = L + i as i64;
        let d = apple.abs();

        if min_d > d {
            min_d = d;
            best = total - apple;
        }
    }

    println!("{}", best)
}


Measured memory_bytes: 4352
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,z;
    char ca,cb,cc;
    cin>>a>>b>>c;
    sum=a+b+c;
    cout<<sum-max(max(a,b),c);

    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 55);
int main(){ 
  int n;
  cin >> n;
  vector<int> a(3*n);
  rep(i,3*n) cin >> a[i];
  vector<ll> l_cum(2*n+1, 0), r_cum(2*n+1, 0);
  priority_queue<int> l_min, r_max;
  for (int i = 0; i < n; i++) {
    l_cum[i+1] = l_cum[i] + a[i];
    l_min.push(-a[i]);
  }
  /*要素をn個に保ちつつ更新していく*/
  for (int i = n; i < 2*n; i++) {
    int d = -1 * l_min.top();
    
    if (a[i] > d) {
      l_cum[i + 1] = l_cum[i] + a[i] - d;
      l_min.pop();
      l_min.push(-a[i]);
    } else l_cum[i + 1] = l_cum[i];

  }

  for (int i = 0; i < n; i++) {
    r_cum[2*n - i - 1] = r_cum[2*n - i] + a[3*n - i - 1];
    r_max.push(a[3*n-1-i]);
  }

  for (int i = n; i < 2*n; i++) {
    int d = r_max.top();

    if (a[3*n - i - 1] < d) {
      r_cum[2*n - i - 1] = r_cum[2*n - i] + a[3*n - i - 1] - d;
      r_max.pop();
      r_max.push(a[3*n-i-1]);
    } else r_cum[2*n-i-1] = r_cum[2*n - i];

  }

  ll res = -INF;
  for (int i = 0; i <= n; i++) {
    res = max(res, l_cum[n + i] - r_cum[i]);
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 5752
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)
typedef long long ll;
 
int main() {
  ll n;cin>>n;
  if (n==1) cout<<"Hello World";
  else {
    ll a,b;cin>>a>>b;
    cout<<a+b;
  }
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
 
#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);
 
#define MOD 1000000007
void init();
void solve();

signed main()
{
    init();
    solve();
}

int N, K;

void init()
{
    cin >> N >> K;
}

void solve()
{
    int res = 1;
    int pos = K-1;
    while (pos < N - 1) {
        pos += K-1;
        res++;
    }
    cout << res << endl;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        try {
            String T = br.readLine();
            String P = br.readLine();
 
            if(P.length() <= T.length()){
 
                char T_array[] = T.toCharArray();
                char P_array[] = P.toCharArray();
 
                boolean Found = false,FLG;
 
                for(int start = 0; start < T.length(); start++){
                    FLG = true;
                    for(int i = 0; i < P.length(); i++){
                        if(P_array[i] != T_array[(start+i)%T.length()]){
                            FLG = false;
                            break;
                        }
                    }
                    if(FLG){
                        Found = true;
                        break;
                    }
                }
 
                if(Found){
                    System.out.printf("Yes\n");
                }else{
                    System.out.printf("No\n");
                }
 
            }else{
 
                System.out.printf("No\n");
            }
 
        } catch (IOException e) {
            e.printStackTrace();
        }
 
 
    }
}


Measured memory_bytes: 24692
// input macro begin
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

fn main() {
    input! {
        n: usize,
        a: [u64;n],
    }

    let mut ans = 0;

    for i in 0..n {
        let mut t = a[i];
        while t % 2 == 0 {
            t /=2;
            ans +=1;
        }
    }

    println!("{}", ans);
}

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

long long pointGenerator(int row, int column, int width){
    return (1LL*row*width)+column;
}

vector<int> getMax(vector<int> &men) {
    int maxSize=0;
    vector<int> ret;
    for(int & i : men) maxSize=max(maxSize, i);
    for(int i=0; i<men.size(); i++){
        if(maxSize==men[i]) ret.push_back(i);
    }
    return ret;
}

int main() {

    int h, w, m;
    scanf("%d%d%d", &h, &w, &m);

    vector<int> x(m), y(m);
    unordered_set<long long> coords;
    vector<int> menInRow(h, 0);
    vector<int> menInColumn(w, 0);

    for(int i=0; i<m; i++){
        scanf("%d%d", &x[i], &y[i]);
        x[i]--, y[i]--;
        coords.insert(pointGenerator(x[i], y[i], w));
        menInRow[x[i]]++;
        menInColumn[y[i]]++;
    }

    vector<int> maxRow = getMax(menInRow), maxCol = getMax(menInColumn);

    long long total=menInRow[maxRow[0]]+menInColumn[maxCol[0]];
    for(auto & currentRow : maxRow){
        for(auto & currentCol : maxCol){
            if(coords.find(pointGenerator(currentRow, currentCol, w))==coords.end()){
                printf("%lld\n", total);
                return 0;
            }
        }
    }
    printf("%lld\n", total-1);
    return 0;
}

/*Logic:
 * This problem was giving me TLE because some of the data structures such as
 * map, set used were slow as their insertion and deletion took logarithmic time.
 *
 * Main idea is that, for any row and column chosen, there are 2 possibilities.
 * 1. The bomb placed at a coordinate where there is no one. In that case,
 * summation of people in both row and column is the answer.
 *
 * 2. The bomb placed at a coordinate where there is a person. In, that case,
 * subtract 1 from summation of people in both row and column because we would be
 * counting the the guy on the bomb coordinates twice.
 *
 * So, all we need to do is to find rows where number of people is maxed.
 * Same goes for columns. In this case, row and column are independent to each other.
 *
 * Now, we know that case 1 is the best case. So we  need to find evidence from all
 * possible combinations of rows and columns where the number of people is maximum for each.
 * Once we have the evidence we can say case 1 is the answer. If no evidence is found, then
 * case 2 is the answer.
 */

Measured memory_bytes: 25684
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<algorithm>
#include<list>
#include<cmath>
#include<iomanip>
#include<queue>
#include<functional>
#include<climits>
#include<iterator>
#include<unordered_set>
#include<unordered_map>
#include<map>
#include<set>
#include<typeinfo>
using namespace std;

const double pi=4*atan(1.0);

constexpr long long mod=static_cast<long long>(1e9+7);

using cWeightEdges=vector<vector<pair<int,int>>>;
using cEdges=vector<vector<int>>;

int main() {
	string str;
	cin>>str;
	for(int i=0;i<4;++i)
		cout<<str[i];
	cout<<" ";
	for(int i=4;i<str.size();++i)
		cout<<str[i];
	cout<<endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
    string week[7] = {"SAT","FRI","THU","WED","TUE","MON","SUN"};
    string s;
    cin >> s;
    for(int i=0;i<7;i++){
        if(s == week[i]){
            cout << i + 1 << endl;
        }
    }
    
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
main(){
  int x,y,w,h,n,tx,ty,cnt,i;
  cin>>x;
  while(cin>>x>>y>>w>>h>>n){
    cnt=0;
    while(n--){
      cin>>tx>>ty;
      if (x<=tx&&tx<=x+w&&y<=ty&&ty<=y+h)cnt++;
    }
    cout <<cnt<< endl;
  }
}

Measured memory_bytes: 0
N=int(input())
A=[int(i) for i in input().split()]
def CountMinusAndZeroAndMin(lis):#マイナスの個数とabs挿話とabs最小の値を返す
    curmin=1000000000000000
    plussum=0
    minus=0
    for i in lis:
        j=abs(i)
        plussum+=j
        curmin=min(j,curmin)
        if i<0:
           minus+=1
    return(minus,plussum,curmin)
minus,plussum,minabs=CountMinusAndZeroAndMin(A)
if minabs==0 or minus%2==0:
    print(plussum)
else:
    print(plussum-2*minabs)

Measured memory_bytes: 14260
def make_list(length, loop):
    result = [[] for _ in range(length)]
    for _ in range(loop):
        a, b = map(lambda x: int(x) - 1, input().split())
        result[a].append(b)
        result[b].append(a)
    return result


def main():
    # 敢えてDFSで解いてみる．
    n, m, k = map(int, input().split())
    friend = make_list(n, m)
    brock = make_list(n, k)
    answer = [0] * n
    group_index = [0] * n
    group_id = 1

    def dfs(index):
        q = [index]
        group_index[index] = group_id
        connection = 1
        while not q == []:
            now = q.pop()
            for f in friend[now]:
                if group_index[f] == 0:
                    connection += 1
                    group_index[f] = group_id
                    q.append(f)
        return connection

    id_and_elements = {}
    for i in range(n):
        if group_index[i] == 0:
            id_and_elements[group_id] = dfs(i)
            group_id += 1

    for i in range(n):
        answer[i] += id_and_elements[group_index[i]] - 1
        answer[i] -= len(friend[i])
        for b in brock[i]:
            if group_index[b] == group_index[i]:
                answer[i] -= 1
    print(" ".join(map(str, answer)))


if __name__ == '__main__':
    main()



Measured memory_bytes: 51720
def main():
    debt = 100000
    n = int(input())
    for i in range(n):
        debt = debt * 1.05
        if debt % 1000 > 0:
            debt = (debt // 1000 * 1000) + 1000
    print(int(debt))

if __name__ == '__main__':
    main()

Measured memory_bytes: 7652
#include<cstdio>
int ans[20005],vis[30005];
inline int gcd(int a,int b){return b?gcd(b,a%b):a;}
int main(){
    int n,cnt=1,sum=0;scanf("%d",&n);
    for(int i=1;cnt<n;i++)
        if(!(i%2)||!(i%3))
            ans[cnt++]=i,vis[i]=1,sum+=i;
    int rem2=sum%2,rem3=sum%3;
    for(int i=1,f=1;f;i++)
        if(!vis[i]&&!((i+rem2)%2)&&!((i+rem3)%3)&&gcd(i,sum)>1)
            ans[cnt++]=i,f=0;
    for(int i=1;i<=n;i++)printf("%d ",ans[i]);
    return 0;
}

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    vector<string> s(2);
    cin >> s[0] >> s[1];
    string ans;
    for (int i = 0; i < (int)s[1].length(); i++) {
        for (int j = 0; j < 2; j++) ans.push_back(s[j][i]);
    }
    if (s[0].length() > s[1].length()) ans.push_back(s[0].back());
    cout << ans << endl;
    return 0;
}


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

int main(){
   int a, b;
   cin >>a >> b;
   vector<int> x(12);
   x = {1,3, 1,2, 1, 2, 1, 1, 2, 1, 2, 1};
   if (x[a-1] == x[b-1]){
      cout << "Yes" << endl;
   }
   else {
      cout << "No" << endl;
   }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include<algorithm>
using namespace std;
int main()
{
	int a, b,k;
	cin >> a >> b >> k;
	int cnt = 0;
	int ans[100];
	int i;
	
	for ( i = 1; i <= max(a, b); i++)
	{
		if (a%i == 0 && b%i == 0) {
			cnt++;
			ans[cnt] = i;
			
		}
	}
	cout << ans[cnt-k+1] << endl;
    return 0;
}

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

#define mem(a,n) memset(a,n,sizeof(a))
#define rep(i,a,n) for(int i=a;i<n;i++)

typedef long long ll;
const double eps=1e-5;
const int N=2e5+5;
const int INF=0x3f3f3f3f;
const int dir[4][2]= {1,0,-1,0,0,1,0,-1};

struct Node
{
    int xb;
    int x;
    bool operator < (const Node& m)const
    {
        return x<m.x;
    }
} a[N];
int ans[N];
int main()
{
    //freopen("in.txt","r",stdin);
    int T;
    int n;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&a[i].x);
        a[i].xb=i;
    }
    sort(a+1,a+n+1);
    /*for(int i=1; i<=n; i++)
    {
        printf("i=%d %d %d\n",i,a[i].xb,a[i].x);
    }*/
    int mid=(n+1)/2;
    int m1=a[mid].x;
    int m2=a[mid+1].x;
    //printf("mid=%d m1=%d\n",mid,m1);
    int cnt=0;
    for(int i=1; i<=n; i++)
    {
        int tmpx=a[i].x;
       // int tmpx=a[tmp].x;
        //printf("tmp=%d tmpx=%d\n",tmp,tmpx);
        //printf("%d  mid=%d\n",a[tmp].x,mid);
        if(tmpx<=m1) ans[a[i].xb]=a[mid+1].x;
        else ans[a[i].xb]=a[mid].x;
    }
    for(int i=1;i<=n;i++)
        printf("%d ",ans[i]);
    return 0;
}


Measured memory_bytes: 4480
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    int a1=0,a2=0,a4=0,n,m,i;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&m);
        if(m%4==0)
        a4++;
        else if(m%2==0)
            a2++;
        else a1++;
    }
 
    if(a2==0&&a1==a4+1)
        printf("Yes\n");
    else if(a4>=a1)
        printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
const int mx=3e4;
bool used[mx+10];
vector<uli>all;
int n;
int main(){
  vector<int>t;
  for(int i=1;i<=mx;i++)if(i%3==0 && i%2!=0)t.push_back(i);
  if(t.size()%2==1)t.pop_back();
  reverse(t.begin(),t.end());
  cin>>n;
  if(n==3){
    puts("2 5 63");
    return 0;
  }
  if(n==4){
    puts("2 5 20 63");
    return 0;
  }
  all.push_back(2);
  int rem=n-2;
  if((n-1)%2==0){
    all.push_back(4);
    rem--;
  }
  assert(rem%2==0);
  while(rem>0 && !t.empty()){
    all.push_back(t.back());    
    t.pop_back();
    rem--;
  }
  used[0]=true;
  for(int x:all)used[x]=true;
  int x=2;
  while(rem>0){
    while(used[x])x+=2;
    all.push_back(x);
    used[x]=true;
    rem--;
  }
  uli sm=0;
  for(int x:all)sm+=x;
  uli v=((sm+5)/6ll)*6ll;
  uli y=v-sm;
  while(used[y])y+=6;
  all.push_back(y);
  for(int i=0;i<n;i++){
    if(i!=0)printf(" ");
    printf("%lld",all[i]);
  }
  puts("");
  return 0;
}


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

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

  sort(a, a + 2 * n);
  long long ans = 0;
  for (int i=0; i<n; i++) {
    ans += a[2*i];
  }
  cout<<ans<<endl;
}

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

int a[500+50];
int x[100000+50],l[100000+50];
vector <pair <int,int> > v;
signed main(){
    ios::sync_with_stdio(false);
    
	int n,k,s;
	cin>>n>>k>>s;
	int other=(s%1000000000)+1;
	for(int i=0;i<n;i++){
		if(i<k){
			cout<<s<<" ";
		}
		else{
			cout<<other<<" ";
		}
	}
	

}
/*

Mistakes to take care of-

1. For string s, s+=a is similar to appending to s. s = s + a takes O|s| + O|a| time. 
Relevant problem where I made mistake - https://codeforces.com/contest/1326/problem/D2

2. Try using constant value of N to declare arrays, etc. Else you might get hacked / FST.
Relevant problem where I made a mistake - https://codeforces.com/contest/1307/problem/D

3. While exponentiation, avoid modding the exponent. Or mod with mod-1.
Relevant problem where I made a mistake - https://codeforces.com/contest/1332/problem/E

4. modulo operator (%) in c++ returns the sign of the divisor.
Eg. (-1%8) = -1
Relevant problem where I made a mistake - https://codeforces.com/contest/1345/submission/79809463
*/

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

int main() 
{
	int n, limi;
	cin >> n >> limi;
	int v[n + 1], ans[51][51][101];
	for (int i = 1; i <= n; i++) cin >> v[i];
	
	for (int i = 1; i <= n; i++)
	{
		ans[i][i][0] = 0;
		for (int k = 1; k <= limi; k++) ans[i][i][k] = max(0, v[i]);
		
		for (int j = i - 1; j >= 1; j--)
		{
			ans[j][i][0] = 0;
			ans[j][i][1] = max({0, v[i], v[j]});
			for (int k = 2; k <= limi; k++)
				ans[j][i][k] = max({ans[j][i - 1][k - 1] + v[i], 
									ans[j][i - 1][k - 2], 
									ans[j + 1][i][k - 1] + v[j],
									ans[j + 1][i][k - 2], 0});
		}
	}
	cout << ans[1][n][limi];
}

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

int main()
{
    int a, b;
    cin >> a >> b;

    if ((a % 2 == 0) || (b % 2 == 0))
    {
        cout << "Even" << endl;
    }
    else
    {
        cout << "Odd" << endl;
    }

    return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, ll> pcl;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(mp(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define mp make_pair
#define pb push_back
#define INF (1 << 29)
const int mod = 1000000007;

int main() {
    char ch;
    cin >> ch;
    if(ch >= 'a' && ch <= 'z') {
        cout << 'a' << endl;
    } else {
        cout << 'A' << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>

using namespace std;

bool IsPrime[50010];
vector<int> Prime;

void PrimeCalc()
{
	for(int i = 0; i < 50010; ++i)
	{
		IsPrime[i] = true;
	}
	IsPrime[0] = IsPrime[1] = false;
	for(int i = 2; i < 50010; ++i)
	{
		if(IsPrime[i])
		{
			Prime.push_back(i);
			for(int j = 2 * i; j < 50010; j += i)
			{
				IsPrime[j] = false;
			}
		}
	}
}

void solve()
{
	PrimeCalc();
	int n;
	while(cin >> n, n)
	{
		int a = n / 2;
		int b = Prime.size();
		int count = 0;
		for(int i = 0; i <= b; ++i)
		{
			if(n < Prime[i] || Prime[i] > a)
			{
				break;
			}
			if(IsPrime[n - Prime[i]])
			{
				++count;
			}
		}
		cout << count << endl;
	}
}

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

Measured memory_bytes: 1008
import java.util.*;

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

		int ans = 0;
		ans = r * x - d;
		System.out.println(ans); 
		for(int i = 0; i <= 8; i ++){
			ans = r * ans - d;
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 23124
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <functional>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int N, K, cnt[100000];
pll dt[100000];

int main() {
    ll d, t;
    cin >> N >> K;
    REP(i, N) {
        cin >> t >> d;
        dt[i] = {d, t - 1};
    }
    sort(dt, dt + N, greater<pll>());

    ll base = 0, kind = 0;
    priority_queue<pll, vector<pll>, greater<pll>> sushi;
    REP(i, K) {
        if (cnt[dt[i].second] == 0) kind++;
        cnt[dt[i].second]++;
        base += dt[i].first;
        sushi.push(dt[i]);
    }
    ll ans = base + kind * kind;

    FOR(i, K, N) {
        if (cnt[dt[i].second] != 0) continue;

        while (!sushi.empty()) {
            pll p = sushi.top(); sushi.pop();

            if (cnt[p.second] > 1) {
                cnt[dt[i].second]++;
                cnt[p.second]--;
                base = base - p.first + dt[i].first;
                kind++;
                ans = max(ans, base + kind * kind);
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4340
#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;
int main() {
    int N;
    cin >> N;
    int a[N];
    REP(i, N) cin >> a[i];
    int next_button = a[0];
    int cnt = 0;
    REP(i, N){
        cnt++;
        if(next_button == 2) {
            cout << cnt << "\n";
            return 0;
        }
        next_button = a[next_button - 1];
    }
    cout << -1 << "\n";
}

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

int main(){
    int a,b;
    double c;
    cin >>a>>b;
    c=1.00000*a/b;
    cout << a/b << " "<< a%b << " ";
    printf("%.5lf",c);
    cout <<endl;
    
}


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

using namespace std;

int n, m;
bool check (int x) {
    int cur = m - n * x;
    return cur % x == 0;
}

int main(){
    cin >> n >> m;

    for (int i = m / n; i >= 1; i--) if (check(i)) return cout << i, 0;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <tuple>
#include <queue>
#include <bitset>
#include <unordered_map>
#include <tuple>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <sys/time.h>

using namespace std;

void solve(long long L, vector<long long> A){
  vector< vector<long long> > dp(L, vector<long long>(5, 0));
  vector<long long> a = {0, 2, 1, 2, 0};
  for (int i = 0; i < 5; i++) {
    switch (i) {
      case 0:
        dp[0][i] = - A[0];
        break;
      case 1:
        dp[0][i] = - (abs(A[0]-2)%2);
        break;
      case 2:
        dp[0][i] = - (abs(A[0]-1)%2);
        break;
      case 3:
        dp[0][i] = - (abs(A[0]-2)%2);
        break;
      case 4:
        dp[0][i] = - A[0];
        break;
    }
  }
  for (int i = 1; i < L; i++) {
    for (int j = 0; j < 5; j++) {
      if (j == 0 || j == 4) {
        dp[i][j] = *max_element(dp[i-1].begin(), dp[i-1].begin()+1+j) - A[i];
      } else {
        if (A[i] == 0) {
          dp[i][j] = *max_element(dp[i-1].begin(), dp[i-1].begin()+1+j) - abs(A[i]-a[j]);
        } else {
          dp[i][j] = *max_element(dp[i-1].begin(), dp[i-1].begin()+1+j) - (abs(A[i]-a[j])%2);
        }
      }
    }
  }
  std::cout << - *max_element(dp[L-1].begin(), dp[L-1].end()) << std::endl;
}

int main(){
  long long L;
  scanf("%lld",&L);
  vector<long long> A(L);
  for(int i = 0 ; i < L ; i++){
    scanf("%lld",&A[i]);
  }
  solve(L, A);
  return 0;
}


Measured memory_bytes: 17512
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

const int MAX = 5100000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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()
{
	COMinit();
	double X,Y;
	cin>>X>>Y;
	double a,b;
	unsigned long long int ans;
	a = (2*Y - X)/3;
	b = (2*X - Y)/3;
	
	if( ( (a -(int)a) == 0) && ( (b - (int)b) == 0)){
		ans = COM(a+b,a);
	}else{
		ans = 0;
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 119808
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef long double ld;
typedef vector<ll>VI;
typedef pair<ll,ll>P;
#define VV(T) vector<vector<T>>
#define sz(x) int(x.size())
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=max(x,a)
#define chmin(x,a) x=min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX6 1001001//6
#define MAX7 10010010//7
#define SENTINEL 2000000000//9
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define CLR(mat) memset(mat, 0, sizeof(mat))
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
template<class T> bool contain(const std::string& s, const T& v) {
   return s.find(v) != std::string::npos;
}
using Edge=pair<int,ll>;
using Graph=vector<vector<ll> >;//ll or Edge
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// sort_reverse -> greater<long long>()
// vector型から重複を削除 list.erase(unique(ALL(list)),list.end());
// g++ -o a a.cpp -Wall -lm -std=c++17
//push_back -> emplace_back

int main(){
   int a[3];rep(i,3)cin>>a[i];
   sort(a,a+3);
   int left=2*a[2]-(a[1]+a[0]);
   cout<<(left%2?(left+3)/2:left/2)<<endl;
   
}

Measured memory_bytes: 3612
#include <iostream>
#include <stdlib.h>
using namespace std;

int main() {
    int n;
    int w[100];
    int a, b;
    int t;

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

    int x = 1, y = n-2;

    for(int i = 0; i < n-2 ; i++){
        if (a > b) {
            b = b + w[y];
            y--;
        }
        else {
            a = a + w[x];
            x++;
        }
    }

    cout << abs(a-b) << "\n";

    return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

    ll N,M;
    string S;
    cin >> N>>M;

    if(N>M){
        swap(N, M);
    }

    if(N==1){
        if(M==1){
            cout << 1 << endl;
        }
        else if(M==2){
            cout << 0 << endl;
        }
        else{
            cout << M - 2 << endl;
        }
    }
    else if(N==2){
        cout << 0 << endl;
    }
    else{
        cout << (N-2)*(M-2) << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
const int MAXV = 1e5 + 5;
void marmot0814() {
    int n, W; cin >> n >> W;
    vector<LL> dp(MAXV + 1, INF);
    dp[0] = 0;
    while (n--) {
        LL w, v; cin >> w >> v;
        for (int i = MAXV ; i >= v ; i--)
            dp[i] = min(dp[i], dp[i - v] + w);
    }
    int ans = 0;
    for (int i = 0 ; i <= MAXV ; i++)
        if (dp[i] <= W)
            ans = i;
    cout << ans << '\n';
}
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int t = 1, kase = 0; // cin >> t;
    while (t--) {
        // cout << "Case #" << ++kase << ":";
        marmot0814();
    }
}

Measured memory_bytes: 3968
#include<stdio.h>
int main(void)
{
	int n,a[10000],i,j,cnt;
	scanf("%d",&n);
	while(n!=0){
		cnt=0;
		for(i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		for(j=0;j<10;j++){
			for(i=0;i<n;i++){
				if(a[i]==j){
					printf("*");
					cnt++;
				}
			}
			if(cnt==0){
				printf("-");
			}
			printf("\n");
			cnt=0;
		}
		scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define MOD(x) ((x)%mod)
int n;
long long mean;
long long a[200005]; 
long long s[200005]; 
long long temp[200005]; 
long long ans;
void merge(int l,int r)
{
	int m=(l+r)/2;
	int h1=l,h2=m+1;
	int t1=m,t2=r;
	if(h1<t1) merge(h1,t1);
	if(h2<t2) merge(h2,t2);
	for(int i=l;i<=r;i++)	
	{
		if(h1<=t1&&h2<=t2)
		{
			if(s[h1]>s[h2])
			{
				temp[i]=s[h1++];
			}
			else
			{
				temp[i]=s[h2++];
				ans+=t1-h1+1;
			}
		}
		else if(h1<=t1)
		{
			temp[i]=s[h1++];
		}
		else
		{
			temp[i]=s[h2++];
		}
	}
	for(int i=l;i<=r;i++)
		s[i]=temp[i];
}
int main()
{
	scanf("%d%lld",&n,&mean);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		a[i]-=mean;
		s[i]=s[i-1]+a[i];
	}
	merge(1,n);
	for(int i=1;i<=n;i++)
		if(s[i]>=0) ans++;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 4992
import java.util.*;

public class Main {

	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int ar[]=new int[n];
		for(int i=0;i<n;i++) ar[i]=sc.nextInt();
		
		long preh=ar[0],table,ans=0;
		for(int i=0;i<n;i++)
		{
			table=preh-ar[i];
			if(table<0) table=0;
			ans+=table;
			preh=table+ar[i];
		}
		System.out.println(ans);
	}
	
}


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

using namespace std;
using ll = long long int;
#define long ll

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

    ll n;
    cin >> n;
    vector<string> s(n);
    for(auto &l: s) cin >> l;

    {
        bool ok = false;
        for(ll i=0; i<n; i++)
        for(ll j=0; j<n; j++) {
            ok |= s[i][j] == '#';
        }
        if(!ok) {
            cout << -1 << endl;
            return 0;
        }
    }

    string cor(n, '.');
    string cand(n, '#');
    for(ll i=0; i<n; i++)
    for(ll j=0; j<n; j++) {
        if(s[i][j] == '#') cor[j] = '#';
        if(s[i][j] == '.') cand[j] = '.';
    }
    ll cntand = 0;
    for(ll i=0; i<n; i++)
        cntand += cand[i] == '#';

    vector<ll> cnt(n);
    for(ll i=0; i<n; i++)
    for(ll j=0; j<n; j++)
        if(s[i][j] == '.') cnt[i]++;

    ll r = 1e9;
    for(ll i=0; i<n; i++) {
        ll t = (cor[i] == '#' ? 0 : 1) + cnt[i] + (n - cntand);
        r = min(t, r);
    }
    cout << r << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;//10^12
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
const double EPS=1E-8;
////////////////////////////////////////

double ans=0;
int k;
double limr,liml,p,e,t;
void dfs(int c,double r,double l,double po){
    double m=(r+l)/2;
    if(c==k){
        if(limr<=m&&m<=liml)ans+=po;
        return;
    }
    c++;
    if(l<=limr||liml<=r)return;
    if(limr<r&&l<liml){
        ans+=po;return;
    }
    if(m<t){
        dfs(c,r,m,po*p);
        dfs(c,m,l,po*(1-p));
    }else{
        dfs(c,r,m,po*(1-p));
        dfs(c,m,l,po*p);
    }
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    
    double r,l;cin>>k>>r>>l>>p>>e>>t;
    limr=t-e;liml=t+e;
    dfs(0,r,l,1);
    printf("%1.10lf",ans);
    
    return 0;
}


Measured memory_bytes: 3304
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<int, int>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int k;
    cin, k;
    ll sum = 0;
    REP(a, 1, k + 1) {
        REP(b, 1, k + 1) {
            REP(c, 1, k + 1) {
                sum += gcd(a, gcd(b, c));
            }
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3652
def call(num):
  ans=[]
  for i in range(1,n+1):
    if i%3==0:
      ans.append(i)
    else:
      tmp=i
      flag=False
      while tmp>0:
        if tmp%10==3:
          flag=True
        tmp=tmp//10
      if flag:
        ans.append(i)
  print(' '+' '.join(map(str,ans)))

n=int(input())
call(n)


Measured memory_bytes: 6108